-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping problem on a difficult database
PostPosted: Fri Nov 14, 2008 8:38 am 
Newbie

Joined: Fri Nov 14, 2008 7:56 am
Posts: 1
Hibernate version: 3
Name and version of the database you are using: Oracle 10

Hi to everyone,
I'm writing because I have a mapping problem. I've already read concernig chapter in "Java persistence with Hibernate" and searched with google, but it seems to be a very particular mapping case.

I have this two tables:

T_FIRST
----------
PKEY1
PKEY2
DATA
CODE

T_SECOND
-------------
ID
DATA

The first table has a composite primary key formed by PKEY1 and PKEY2, CODE brings important data for the first table but it's also the join field with second table on ID field and it is nullable.
In Java class TFirst I need the code field and I need the TSecond type object which must be insertable and updatable, so I couldn't use a many-to-one with update-"false" insert="false"

I try this mapping in TFirst.hbm.xml

Mapping documents:
Code:
<join table="T_SECOND" optional="true">
    <key column="id" property-ref="code"/>
    ... -> I tried differents ways there
</join>


I think it would be correct, because with column="id" I say to hibernate to use the id column on T_SECOND as join field and with property-ref="code" I say to use the code field instead the [pkey1,pkey2] primary key on TFirst class. But it seems like property-ref attribute is ignored because if I write it or if I don't write it the error trace is the same. If I do the same kind of mapping of column and property-ref in a many-to-one mapping it works, but unfortunatly it's not useful for me :(

Full stack trace of any exception that occurs:
Exception in thread "main" java.lang.ExceptionInInitializerError
at idealista.dp.hibernate.HbnDao.open(HbnDao.java:358)
at idealista.dp.data.sedes.SedesHbnDao.getSedeByCodCliente(SedesHbnDao.java:94)
at idealista.Test.main(Test.java:71)
Caused by: org.hibernate.MappingException: Foreign key (FK5358D1892AF2CEE7:T_SECOND [id])) must have same number of columns as the referenced primary key (T_FIRST [PKEY1,PKEY2])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1263)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at idealista.dp.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:38)
... 3 more

Thanks to everyone who can help me.


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.