Hey guys,
I've found a bug in the "Compound Primary Keys" implementation in 
JBoss/Hibernate EJB3. I've been able to reproduce this problem on JBoss 4.0.4GA 
and jboss-EJB-3.0_Embeddable_ALPHA_9. Current implementation generates extra 
field from compound key. This is an example from Sun's "The Java EE 5 Tutorial" 
http://java.sun.com/javaee/5/docs/tutorial/doc/PersistenceEJB2.html

  | @IdClass(order.entity.LineItemKey.class)
  | @Entity
  | @Table(name = "EJB_ORDER_LINEITEM")
  | public class LineItem {
  |   @Id
  |   public int getItemId() {
  |     return itemId;
  |   }
  |   @Id
  |   @Column(name="ORDERID", nullable=false, insertable=false, updatable=false)
  |   public Integer getOrderId() {
  |     return orderId;
  |   } 
  | }
  | 
  | public final class LineItemKey implements  java.io.Serializable {
  | 
  |   private Integer orderId;
  |   private int itemId;
  | ...
  |     public Integer getOrderId() {
  |         return orderId;
  |     }
  | ...
  | }
  | 
This generates following SQL in logs:

  | DEBUG [org.hibernate.persister.entity.AbstractEntityPersister]  Snapshot 
select: select lineitem_.orderId, lineitem_.itemId, lineitem_.ORDERID as 
ORDERID9_, lineitem_.quantity as quantity9_, lineitem_.VENDORPARTNUMBER as 
VENDORPA4_9_ from EJB_ORDER_LINEITEM lineitem_ where lineitem_.orderId=? and 
lineitem_.itemId=?
  | DEBUG [org.hibernate.persister.entity.AbstractEntityPersister]  Insert 0: 
insert into EJB_ORDER_LINEITEM (ORDERID, quantity, VENDORPARTNUMBER, orderId, 
itemId) values (?, ?, ?, ?, ?)
  | DEBUG [org.hibernate.persister.entity.AbstractEntityPersister]  Update 0: 
update EJB_ORDER_LINEITEM set ORDERID=?, quantity=?, VENDORPARTNUMBER=? where 
orderId=? and itemId=?
  | DEBUG [org.hibernate.persister.entity.AbstractEntityPersister]  Delete 0: 
delete from EJB_ORDER_LINEITEM where orderId=? and itemId=?
  | 
  | OR
  | 
  | insert into EJB_ORDER_LINEITEM (ORDERID, quantity, VENDORPARTNUMBER, 
orderId, itemId) values (?, ?, ?, ?, ?)
  | 
As you can see there are duplicationg columns: ORDERID from LineItem class and 
orderId from LineItemKey. 
When I add @Column annotation to the LineItemKey:

  | public final class LineItemKey implements  java.io.Serializable {
  | 
  |   private Integer orderId;
  |   private int itemId;
  | ...
  |   @Column(name="ORDERID", nullable=false, insertable=false, updatable=false)
  |   public Integer getOrderId() {
  |     return orderId;
  |   }
  | ...
  | }
  | 
I got exception:

  | org.hibernate.MappingException: Repeated column in mapping for entity: 
order.entity.LineItem column: ORDERID (should be mapped with insert="false" 
update="false")
  |         at 
org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:575)
  | 
I believe this is connected to Hibernate bug HBX-164 
http://opensource.atlassian.com/projects/hibernate/browse/HBX-164
Should I file a bug to JBoss or Hibernate JIRA?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3979240#3979240

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3979240
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to