tags:

views:

67

answers:

1

I'm trying to create a JPA Entity backed by a view which does not have an id. The rows are uniquely defined by two columns, product id and node id. How can I specify that the id for the entity is a multi-column id, and do it using xml, not annotations?

A: 

I was specifying 'id' as the name for my id's, rather than the property names of the Java entity. I had this:

<entity class="com.MyEntity" name="MyEntity">
   <table name="MY_TABLE"/>
   <attributes>
       <id name="id">
           <column name ="NODE_ID" nullable="false"/> 
       </id>
       <id name="id">
           <column name ="PRODUCT_ID" nullable="false"/> 
       </id>
       <basic name="name"><column name="NAME" nullable="false"/></basic>
   </attributes>

It should be this:

<entity class="com.MyEntity" name="MyEntity">
   <table name="MY_TABLE"/>
   <attributes>
       <id name="nodeId">
           <column name ="NODE_ID" nullable="false"/> 
       </id>
       <id name="productId">
           <column name ="PRODUCT_ID" nullable="false"/> 
       </id>
       <basic name="name"><column name="NAME" nullable="false"/></basic>
   </attributes>