As can be read in the previous link to the Hibernate manual there seems to be a handful of solutions for using composite keys in Hibernate. I have a such a business case coming up, but I'm leaning on making the composite keys to be just entity attributes and not rely on these for relations.
For the pizzashop project I decided it was not interesting to really solve at the moment, so I adjusted the roo script for Hibernate and MySQL, created a database in MySQL with name "pizzashop" and granted user "sa" the appropriate permissions and then removed the composite key parts from the original pizzashop.roo script (changed lines in bold):
Code:
// Create a new project
project com.springsource.pizzashop
// Setup JPA persistence using Hibernate and MySQL
jpa setup --provider HIBERNATE --database MYSQL --databaseName pizzashop --userName sa
// Create domain entities
entity --class ~.domain.Base --activeRecord false --testAutomatically
field string --fieldName name --sizeMin 2 --notNull
entity --class ~.domain.Topping --activeRecord false --testAutomatically
field string --fieldName name --sizeMin 2 --notNull
entity --class ~.domain.Pizza --activeRecord false --testAutomatically
field string --fieldName name --notNull --sizeMin 2
field number --fieldName price --type java.math.BigDecimal
field set --fieldName toppings --type ~.domain.Topping
field reference --fieldName base --type ~.domain.Base
entity --class ~.domain.PizzaOrder --testAutomatically --activeRecord false
field string --fieldName name --notNull --sizeMin 2
field string --fieldName address --sizeMax 30
field number --fieldName total --type java.math.BigDecimal
field date --fieldName deliveryDate --type java.util.Date
field set --fieldName pizzas --type ~.domain.Pizza
field string --fieldName shopCountry
field string --fieldName shopCity
field string --fieldName shopName
// Define a repository layer for persistence
repository jpa --interface ~.repository.ToppingRepository --entity ~.domain.Topping
repository jpa --interface ~.repository.BaseRepository --entity ~.domain.Base
repository jpa --interface ~.repository.PizzaRepository --entity ~.domain.Pizza
repository jpa --interface ~.repository.PizzaOrderRepository --entity ~.domain.PizzaOrder
// Define a service/facade layer
service --interface ~.service.ToppingService --entity ~.domain.Topping
service --interface ~.service.BaseService --entity ~.domain.Base
service --interface ~.service.PizzaService --entity ~.domain.Pizza
service --interface ~.service.PizzaOrderService --entity ~.domain.PizzaOrder
// Offer JSON remoting for all domain types trough Spring MVC
json all --deepSerialize
web mvc json setup
web mvc json all
web mvc setup
web mvc all --package ~.web
// Example scripts for JSON remoting:
// curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{name: "Thin Crust"}' http://localhost:8080/pizzashop/bases
// curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '[{name: "Cheesy Crust"},{name: "Thick Crust"}]' http://localhost:8080/pizzashop/bases/jsonArray
// curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '[{name: "Fresh Tomato"},{name: "Prawns"},{name: "Mozarella"},{name: "Bogus"}]' http://localhost:8080/pizzashop/toppings/jsonArray
// curl -i -X DELETE -H "Accept: application/json" http://localhost:8080/pizzashop/toppings/7
// curl -i -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -d '{id:6,name:"Mozzarella",version:1}' http://localhost:8080/pizzashop/toppings
// curl -i -H "Accept: application/json" http://localhost:8080/pizzashop/toppings
// curl -i -H "Accept: application/json" http://localhost:8080/pizzashop/toppings/6
// curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{name:"Napolitana",price:7.5,base:{id:1},toppings:[{name: "Anchovy fillets"},{name: "Mozzarella"}]}' http://localhost:8080/pizzashop/pizzas
// curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{name:"Stefan",total:7.5,address:"Sydney, AU",deliveryDate:1314595427866,id:{shopCountry:"AU",shopCity:"Sydney",shopName:"Pizza Pan 1"},pizzas:[{id:8,version:1}]}' http://localhost:8080/pizzashop/pizzaorders