Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[ hibernate ]composite

 
Hocinema amir
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Is there someone having a full example using composite-id(table with primary composed with 3 fields).
<composite-id name="id" class="CompositeID">
<key-property name="vl" column="city"/>
<key-property name="cp" column="post"/>
<key-property name="adr" column="adr"/>
</composite-id>
I rewrite the equals and hashcode methode, but it is not work.
Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I rewrite the equals and hashcode methode, but it is not work

What's the stacktrace?
There are good examples in the Hibernate docs. http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-4b and http://www.hibernate.org/hib_docs/reference/html/components.html#components-s2-3
Hibernate is not too helpful for composite id support - I think the developers hold the opinion that a database with composite ids need remodelled, which is not always possible.
 
Hocinema amir
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no trace errors, but i can not insert data in database.
Thanks
 
Hocinema amir
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you example using this:
<class name="eg.Foo" table"FOOS">
<composite-id name="compId" class="eg.FooCompositeID">
<key-property name="string"/>
<key-property name="short"/>
<key-property name="date" column="date_" type="date"/>
</composite-id>
<property name="name"/>
....
</class>
Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

but i can not insert data in database

No mapping error? So what is the SQL error - or is it just failing silently? You might want to enable Hibernates JDBC logging in hibernate.properties (see docs) which shows you the actual SQL it is trying to run, if any at all.
 
Hocinema amir
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
My error is:

[ May 03, 2004: Message edited by: Hocinema amir ]
[ May 03, 2004: Message edited by: Hocinema amir ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. This stack trace doesn't seem to relate to an insert operation, or am I misunderstanding soemthing? I can see that there is one Hibernate class (Rloxane) mapped without errors and added to the Configuration, but I don't see any operations on then session (which would usually be logged, unless you have configured the logging ignore these? As you say, there are no errors - turn on Hibernate's JDBC debugging (see docs), write a unit test which adds a new Rloxane object, run it and check:
- that an insert statement is created and run
- that no mapping errors are being generated and silently ignored (unlikely).
 
Hocinema amir
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks For reply.
I don't know why but my program has stopped on:
SessionFactory sf = cfg.buildSessionFactory();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic