-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Autogenerated Composite ID with JSR220
PostPosted: Tue Nov 08, 2005 1:20 pm 
Newbie

Joined: Tue Nov 08, 2005 9:07 am
Posts: 3
Even though you regard this "an extremely strange thing to do" I do have a composite id which can be generated automatically. Basically I have a legacy schema which uses a custom high-low pattern and stores its values in four columns (low value, middle value, high value and some other detail)

Using stock Hibernate I managed to generate composite IDs using CompositeUserType and IdentifierGenerator. Works quite nicely.

However I did not find an appropriate solution using JSR 220 and Hibernate annotations. Do you think this is currently possible?

My hbm.xml snippet:

Code:
<id type="foo.bar.MyCompositeType" name="oid">
  <column name="high"/>
  <column name="middle"/>
  <column name="low"/>
  <column name="other"/>
  <generator class="foo.bar.MyIdGenerator"/>
</id> 


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 7:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Should be doable doing

@Id(...)
@org.hibernate.annotations.GenericGenerator(...)
@org.hibernate.annotations.Type(...)
@org.hibernate.annotations.Columns

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 10:46 am 
Newbie

Joined: Tue Nov 08, 2005 9:07 am
Posts: 3
Thanks Emmanuel,

this is what I tried earlier, to no avail. I get the exception below using the same IdGenerator and CustomeType which work with pure Hibernate.

Jens
PS: I can provide an example if needed.

Code:
2005-11-09 15:31:43,431 [DEBUG] [main] [AnnotationConfiguration] Process annotated classes
2005-11-09 15:31:43,435 [DEBUG] [main] [AnnotationConfiguration] processing manytoone fk mappings
2005-11-09 15:31:43,439 [INFO] [main] [Configuration] processing extends queue
2005-11-09 15:31:43,442 [INFO] [main] [Configuration] processing collection mappings
2005-11-09 15:31:43,444 [INFO] [main] [Configuration] processing association property references
2005-11-09 15:31:43,448 [INFO] [main] [Configuration] processing foreign key constraints

javax.persistence.PersistenceException: org.hibernate.MappingException: identifier mapping has wrong number of columns: foo.bar.MyObject type: foo.bar.MyCompositeType
   at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:149)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:73)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
   at foo.bar.SimpleEntityManagerTest.setUp(SimpleEntityManagerTest.java:27)
   at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
Caused by: org.hibernate.MappingException: identifier mapping has wrong number of columns: foo.bar.MyObject type: foo.bar.MyCompositeType
   at org.hibernate.mapping.RootClass.validate(RootClass.java:194)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:975)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1139)
   at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:358)
   at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:484)
   at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:96)
   at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:142)
   ... 17 more




Code:
@GenericGenerator(name="custom-id", strategy = "foo.bar.MyIdGenerator")
   @Id(generator = "custom-id")
   @Type(type = "foo.bar.MyCompositeType")
   @Columns(
      columns = {
      @Column(name = "high"),
      @Column(name = "middle"),
      @Column(name = "low"),
      @Column(name = "other")
         }
   )


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 2:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
So this is a bug. post a runnable test case in JIRA. Apparently I do not handle @Columns properly for id properties

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 6:11 am 
Newbie

Joined: Tue Nov 08, 2005 9:07 am
Posts: 3
Posted JIRA Issue ANN-142.

http://opensource2.atlassian.com/projec ... se/ANN-142


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.