For developers, functional consultants, and support folks who need to query Hybris data in hAC or Java code. Every example on this page is a real, runnable query.
This is a learning simulator. It runs real SQL against a small practice dataset so every example and exercise executes for real — but actual results in your project depend on your type system, restrictions, and catalog versions.
📦 Meet the data — click to see every table this page queries
Catalog (2)
electronicsProductCatalog
apparelProductCatalog
CatalogVersion (4)
electronics — Staged
electronics — Online
apparel — Staged
apparel — Online
Category (5)
cameras / laptops / phones
accessories
tshirts
Product (12) + VariantProduct (3)
CAM-100, CAM-200, CAM-900 (staged)
LAP-300, LAP-400 (no price), LAP-1000
PHN-500, PHN-600 (unapproved), PHN-1100
ACC-700, ACC-800, TSHIRT-BASE
+ 3 Classic Tee variants (S/M/L)
PriceRow (14)
One per product, INR or USD
LAP-400 deliberately has none
Warehouse (2) + StockLevel (28)
warehouse_mumbai, warehouse_hyderabad
CAM-200 deliberately has no stock rows
LAP-1000 is outOfStock in Mumbai only
Customer (8)
Jane Doe, Raj Kumar, Amelia Wong…
Noah Schmidt deliberately has no orders
Order (10) + OrderEntry (15)
Statuses: CREATED, COMPLETED, CANCELLED
Dates spread 2024-05-02 → 2024-06-27
ArticleApprovalStatus (3)
approved, check, unapproved
CategoryProductRelation (13)
source = Category.pk, target = Product.pk
ACC-700 is deliberately in 2 categories
How the tables connect
Every join you'll write on this page is one of these lines. An arrow always points from a foreign-key column to the pk it references — the same direction you write in a JOIN's ON clause, e.g. {oe:product} = {p:pk}.
Teal = one-to-many, a direct foreign key — the normal case, 10 of the 13 arrows here. Amber = many-to-many, which SAP Commerce always builds from two one-to-many FKs meeting in a small join/line-item table: CPR (CategoryProductRelation) makes Category ⇄ Product many-to-many, and OrderEntry makes Order ⇄ Product many-to-many the same way. One more thing to watch: StockLevel.productCode references Product.code, not Product.pk — not every link in SAP Commerce goes through pk.
One-to-many: one customer, many orders
A solid arrow on the diagram means "many of these can point at one of those." Here, one Customer row can match many Order rows — so a customer with several orders shows up once per order below. Jane Doe appears three times; Raj Kumar twice; everyone else with an order appears once. Noah Schmidt doesn't appear at all — he has zero orders, and a plain JOIN only keeps rows that match on both sides (section 9 covers LEFT JOIN, which would keep him with NULLs instead).
or press Ctrl/Cmd + Enter
10 rows
name
code
status
Amelia Wong
ORD-1004
COMPLETED
Carlos Silva
ORD-1005
COMPLETED
Jane Doe
ORD-1001
COMPLETED
Jane Doe
ORD-1003
CANCELLED
Jane Doe
ORD-1009
COMPLETED
Layla Hassan
ORD-1010
CREATED
Pallavi Paswan
ORD-1007
COMPLETED
Raj Kumar
ORD-1002
COMPLETED
Raj Kumar
ORD-1006
CREATED
Tom Becker
ORD-1008
COMPLETED
Many-to-many: one product, several categories — and back
A join table lets both sides be "many" at once — neither Category nor Product stores the other's pk directly; CategoryProductRelation holds one row per pairing instead. ACC-700 (Camera Strap) is deliberately tagged under two categories, so it proves the relationship both ways:
Product → its categories (expect 2 rows for ACC-700)
or press Ctrl/Cmd + Enter
2 rows
code
accessories
cameras
Category → its products (cameras now includes ACC-700 too)
or press Ctrl/Cmd + Enter
4 rows
code
CAM-100
CAM-200
CAM-900
ACC-700
01
What FlexibleSearch is
FlexibleSearch is SAP Commerce's own query language — SQL-like, but written against your type system (Product, Order, Customer…) instead of raw database tables. You run it in hAC's console, through FlexibleSearchService in Java code, inside ImpEx scripts, and in CMS restriction rules.
02
Basic syntax
Types and attributes both go in curly braces — {Type} for what you're querying, {attribute} for the columns you want back.
or press Ctrl/Cmd + Enter
15 rows
pk
code
8796093000001
CAM-100
8796093000002
CAM-200
8796093000003
LAP-300
8796093000004
LAP-400
8796093000005
PHN-500
8796093000006
PHN-600
8796093000007
ACC-700
8796093000008
ACC-800
8796093000009
CAM-900
8796093000010
LAP-1000
8796093000011
PHN-1100
8796093000012
TSHIRT-BASE
8796094000001
TSHIRT-BASE-S-RED
8796094000002
TSHIRT-BASE-M-BLUE
8796094000003
TSHIRT-BASE-L-GREEN
Try it: add {name[en]} to the SELECT list and run again.
03
Why you always select {pk}
FlexibleSearchService doesn't hand you raw rows — it takes the pk from each result row and loads the real model object for it. Forget {pk} and setResultClassList has nothing to build your models from.
What actually happens under the hood
Your FlexibleSearch query runs against the database and comes back as plain rows of values — numbers and strings, nothing Java-shaped yet.
setResultClassList(List.of(ProductModel.class)) tells the service: "for every row, build me one of these."
To build a ProductModel, the service needs to know which item it's building. It gets that from exactly one place: the pk value in the row. Every other selected column — code, name[en], whatever — is ignored for this purpose.
Using that pk, it loads the full item from the system — all its attributes, localized values, relations — not just the columns you happened to SELECT. Your SELECT list only controlled which rows matched; it never controlled what the resulting model contains.
If a row has no pk column, step 3 has nothing to key off of. FlexibleSearchService throws an exception immediately — it doesn't silently return a half-built object.
So {code} and {name[en]} in the query below aren't "the fields on the returned object" — they're just extra columns in the raw row, unused once pk has done its job of loading the real ProductModel. Try removing {pk} from the query and note what the error-shaped intuition would be: a real call with setResultClassList set would throw at that point.
Without {pk}
Nothing to load a model from. Fine only if you never call setResultClassList with a model class.
SELECT {code} FROM {Product}
→ setResultClassList(ProductModel.class)
→ throws: no pk in result
With {pk}
Each row's pk loads a full ProductModel — code/name in the SELECT just narrowed which rows matched.
Filter rows the same way you would in SQL — =, LIKE, IN, AND / OR.
or press Ctrl/Cmd + Enter
6 rows
code
CAM-100
CAM-200
PHN-500
PHN-600
CAM-900
PHN-1100
IN
or press Ctrl/Cmd + Enter
3 rows
code
CAM-100
LAP-300
PHN-500
05
Parameters
Use ?name instead of hardcoding values — it's safer (no string-building SQL by hand) and lets the platform cache and reuse the query plan across calls with different values.
or press Ctrl/Cmd + Enter
1 row
code
name_en
CAM-100
Compact Camera X100
Try it: change the ?code value in the Parameters panel and rerun.
06
Localized attributes
Attributes that store a value per language take a language code in brackets: {name[en]} vs {name[de]}.
or press Ctrl/Cmd + Enter
5 rows
code
name_en
name_de
cameras
Cameras
Kameras
laptops
Laptops
Laptops
phones
Phones
Telefone
accessories
Accessories
Zubehoer
tshirts
T-Shirts
T-Shirts
07
ORDER BY and limiting results
Sort with ORDER BY same as SQL. For limits, hAC has a separate Max count field below the editor — in Java it's query.setCount(n) (and setStart(n) to page). Try it below.
or press Ctrl/Cmd + Enter
5 rows
code
onlineDate
TSHIRT-BASE
2023-06-01
PHN-1100
2023-05-15
LAP-1000
2023-05-01
PHN-600
2023-04-18
PHN-500
2023-04-05
08
Catalog versions
This is the #1 real-world mistake: forget to filter by catalog version, and you'll get both Staged and Online rows back. "CAM-900" only exists in Staged — watch it appear below.
Without a version filter (the mistake)
or press Ctrl/Cmd + Enter
3 rows
code
CAM-100
CAM-200
CAM-900
Filtered to Online (the fix)
or press Ctrl/Cmd + Enter
2 rows
code
CAM-100
CAM-200
09
Joins
Joins live inside the FROM braces, with aliases so you can qualify attributes as {alias:attribute}.
JOIN
or press Ctrl/Cmd + Enter
10 rows
code
name
ORD-1001
Jane Doe
ORD-1002
Raj Kumar
ORD-1003
Jane Doe
ORD-1004
Amelia Wong
ORD-1005
Carlos Silva
ORD-1006
Raj Kumar
ORD-1007
Pallavi Paswan
ORD-1008
Tom Becker
ORD-1009
Jane Doe
ORD-1010
Layla Hassan
LEFT JOIN — products with no price row
or press Ctrl/Cmd + Enter
1 row
code
LAP-400
10
Relations
Many-to-many links like category ↔ product live in their own relation type, with source and target columns — join through it like any other type.
or press Ctrl/Cmd + Enter
4 rows
code
CAM-100
CAM-200
CAM-900
ACC-700
11
Enums
Enum attributes store a pk, not a string — comparing {approvalStatus} to 'approved' directly will quietly match nothing. Look the code up with a subquery instead.
or press Ctrl/Cmd + Enter
1 row
code
PHN-600
12
Subtypes
{Product} includes subtypes like VariantProduct. Add ! — {Product!} — to get exactly that type and nothing else.
{Product} — includes the 3 Classic Tee variants
or press Ctrl/Cmd + Enter
15 rows
pk
code
8796093000001
CAM-100
8796093000002
CAM-200
8796093000003
LAP-300
8796093000004
LAP-400
8796093000005
PHN-500
8796093000006
PHN-600
8796093000007
ACC-700
8796093000008
ACC-800
8796093000009
CAM-900
8796093000010
LAP-1000
8796093000011
PHN-1100
8796093000012
TSHIRT-BASE
8796094000001
TSHIRT-BASE-S-RED
8796094000002
TSHIRT-BASE-M-BLUE
8796094000003
TSHIRT-BASE-L-GREEN
{Product!} — base products only
or press Ctrl/Cmd + Enter
12 rows
pk
code
8796093000001
CAM-100
8796093000002
CAM-200
8796093000003
LAP-300
8796093000004
LAP-400
8796093000005
PHN-500
8796093000006
PHN-600
8796093000007
ACC-700
8796093000008
ACC-800
8796093000009
CAM-900
8796093000010
LAP-1000
8796093000011
PHN-1100
8796093000012
TSHIRT-BASE
13
Subqueries
Wrap a nested query in double braces: {{ SELECT ... }}. Handy for "none of these" checks.
Products with no stock anywhere
or press Ctrl/Cmd + Enter
1 row
code
CAM-200
Customers who never ordered
or press Ctrl/Cmd + Enter
1 row
name
Noah Schmidt
14
Aggregates
COUNT, SUM, GROUP BY, and HAVING work exactly like SQL — group by an attribute, then filter the groups.
or press Ctrl/Cmd + Enter
3 rows
name
total
Jane Doe
219493
Carlos Silva
92997
Raj Kumar
64999
15
Using it in Java
Same query text, run from a service bean. Not runnable here — just the shape you'll actually type.
JAVA
final String fsq =
"SELECT {pk} FROM {Product} WHERE {code} = ?code";
final FlexibleSearchQuery query = new FlexibleSearchQuery(fsq);
query.addQueryParameter("code", "CAM-100");
query.setResultClassList(List.of(ProductModel.class));
query.setCount(50);
final SearchResult<ProductModel> result =
flexibleSearchService.search(query);
final List<ProductModel> products = result.getResult();
16
Restrictions & session context
In a real storefront, session context (current user, catalog version, language) silently narrows every query through configured restrictions — so the same FlexibleSearch query can return different rows for different users. hAC runs as an admin session with restrictions off by default, which is exactly why a query that "works in hAC" can behave differently from the storefront.
Common mistakes
Forgetting the catalog version filterYou'll get Staged and Online rows mixed together — see section 8.
Hardcoding values instead of parametersUse ?name, not string-concatenated literals.
Comparing an enum to a plain stringEnum attributes store a pk — look the code up with a subquery, see section 11.
Using {'{Product}'} when you meant {'{Product!}'}Non-exact types silently include subtypes like VariantProduct.
Selecting columns instead of {'{pk}'}If you need model objects back, pk has to be in the SELECT list.
Running heavy, unlimited queries in production hACAlways set a Max count — hAC runs as admin with no query timeout by default.
Cheat sheet
Syntax
What it does
Example
{Type}
A type, including its subtypes
FROM {Product}
{Type!}
Exactly that type, no subtypes
FROM {Product!}
{Type AS a}
Type with an alias
FROM {Product AS p}
{a:attr}
Attribute qualified by alias
{p:code}
{attr[lang]}
A localized attribute
{name[en]}
JOIN / LEFT JOIN
Inside the FROM braces, with ON
{A AS a JOIN B AS b ON ...}
{{ }}
A subquery
WHERE {pk} IN {{ SELECT ... }}
?name
A named parameter
WHERE {code} = ?code
Max count
Row limit (hAC field / Java setCount)
query.setCount(50)
Coming from SQL
In SQL
In FlexibleSearch
SELECT col FROM table
SELECT {attribute} FROM {Type}
WHERE col = 'x'
WHERE {attribute} = ?param
INNER JOIN t2 ON t1.x = t2.y
JOIN inside the FROM braces
a bare column name
always wrapped: {attribute}
LIMIT n
Max count field / setCount(n)
FlexibleSearch Console
A blank scratchpad, styled like hAC — write anything, set a max count, and run it against the same practice data.