-->
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.  [ 4 posts ] 
Author Message
 Post subject: Help OneToOne, ManyToOne, JoinTable and the generated SQL...
PostPosted: Thu Jul 05, 2007 12:56 pm 
Newbie

Joined: Thu Jul 05, 2007 12:44 pm
Posts: 3
Hibernate version:
Hibernate : 3.2.4.sp1
Hibernate Annotations : 3.3.0.ga
Hibernante EntityManager : 3.3.1.ga

Mapping documents:

The First Object :

@Entity
@Table(name="DOSSIER")
@SequenceGenerator(name="SEQ_GEN", sequenceName="SEQ_DOSSIER", allocationSize=1)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Dossier extends Modifiable implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(name = "CODE_DOSSIER")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_GEN")
protected Long code;

@OneToOne(mappedBy = "dossier", optional = true, fetch=FetchType.LAZY)
protected PosteActuel posteActuel;

constructor, getters and setters...


}


Second Object (Please note ce joint table Activite member)

@Entity
@Table(name = "POSTE_ACTUEL")
public class PosteActuel implements Serializable {

@Id
@Column(name = "CODE_POSTE_AC")
protected Long code;

@OneToOne(cascade = CascadeType.ALL, optional = true)
@LazyToOne(LazyToOneOption.PROXY)
@Fetch(value=FetchMode.SELECT)
@JoinColumn(name = "CODE_DOSSIER")
protected Dossier dossier;

@ManyToOne(fetch=FetchType.LAZY)
@JoinTable(name = "LIEN_POSTE_DIR",
joinColumns = {@JoinColumn(name = "CODE_POSTE_AC")},
inverseJoinColumns = {@JoinColumn(name = "CODE_ACTIVITE")}
)
@Fetch(value=FetchMode.SELECT)
protected Activite activite;

constructor, getters and setters...
}

Code between sessionFactory.openSession() and session.close():
Transaction tx = session.beginTransaction();
tx.begin();
Dossier d = (Dossier) session.load(Dossier.class, 5235L);
d.getPosteActuel(); //BING !!!
tx.commit();
Full stack trace of any exception that occurs:
[05/07/07 18:40:36 944] DEBUG SQL - select dossier0_.CODE_DOSSIER as CODE1_1_0_, dossier0_.DATE_MODIF as DATE2_1_0_, dossier0_.USER_MODIF as USER3_1_0_, dossier0_1_.CODE_POSTE_AC as CODE0_8_0_ from DOSSIER dossier0_ left outer join LIEN_POSTE_DIR dossier0_1_ on dossier0_.CODE_DOSSIER=dossier0_1_.CODE_DOSSIER where dossier0_.CODE_DOSSIER=?
[05/07/07 18:40:37 084] INFO DefaultLoadEventListener - Error performing load command
org.hibernate.exception.SQLGrammarException: could not load an entity: [com.accor.profiles.model.dossier.Dossier#5235]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1874)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.loader.entity.BatchingEntityLoader.load(BatchingEntityLoader.java:82)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:98)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:836)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:66)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at com.accor.profiles.model.dossier.Dossier$$EnhancerByCGLIB$$130f8e2e.getPosteActuel(<generated>)
at com.accor.profiles.test.TestPersistence.testDossierPosteActuelRelation(TestPersistence.java:642)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.SQLException: ORA-00904: "DOSSIER0_1_"."CODE_DOSSIER" : identificateur non valide

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1986)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:880)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2516)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2850)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:537)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
... 33 more
[05/07/07 18:40:37 100] WARN TestPersistence - org.hibernate.exception.SQLGrammarException: could not load an entity: [com.accor.profiles.model.dossier.Dossier#5235]

Name and version of the database you are using:
Oracle 10g
The generated SQL (show_sql=true):
select dossier0_.CODE_DOSSIER as CODE1_1_0_, dossier0_.DATE_MODIF as DATE2_1_0_, dossier0_.USER_MODIF as USER3_1_0_, dossier0_1_.CODE_POSTE_AC as CODE0_8_0_ from DOSSIER dossier0_ left outer join LIEN_POSTE_DIR dossier0_1_ on dossier0_.CODE_DOSSIER=dossier0_1_.CODE_DOSSIER where dossier0_.CODE_DOSSIER=?


I cannot understand why hibernate is trying to join the DOSSIER table whi th the LIEN_POSTE_DIR table !!!


What I'm doing wrong ?

Tanks for your help in advance.


Pierrot.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 3:36 am 
Newbie

Joined: Thu Jul 05, 2007 12:44 pm
Posts: 3
To complete my question :

1) If I comment the Activite mapping in the PosteActuel class, everything works fine.
2) If instead of using Annotations I map the classes using hbm.xml files,
everything works fine (including the join table with the Activite class)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 12:18 pm 
Newbie

Joined: Thu Jul 05, 2007 12:44 pm
Posts: 3
No answer ?

My question is dumb ? Not enough informations ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 12:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, I'm not sure a birirectional one to one with a join table is supported.
Can you try with @OneToOne instead of @ManyToOne (the later being inconsistent)

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.