jQuery in Action, 2nd edition*
The moose likes Object Relational Mapping and the fly likes [ hibernate ]composite Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "[ hibernate ]composite" Watch "[ hibernate ]composite" New topic
Author

[ hibernate ]composite

Hocinema amir
Greenhorn

Joined: Apr 19, 2004
Posts: 15
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


Hocinema
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Hocinema amir
Greenhorn

Joined: Apr 19, 2004
Posts: 15
I have no trace errors, but i can not insert data in database.
Thanks
Hocinema amir
Greenhorn

Joined: Apr 19, 2004
Posts: 15
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

Joined: Apr 14, 2004
Posts: 10336


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

Joined: Apr 19, 2004
Posts: 15
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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Apr 19, 2004
Posts: 15
thanks For reply.
I don't know why but my program has stopped on:
SessionFactory sf = cfg.buildSessionFactory();
 
Don't get me started about those stupid light bulbs.
 
subject: [ hibernate ]composite
 
Similar Threads
Sequnce in hibernate
Hbm2JavaTask won't generate composite user types correctly
composite key in annotations
Object Relational Mapping Help
Relationship between two table having composite keys on both the sides