ERLEDIGT
NEIN
NEIN
ANTWORTEN
1
1
ZUGRIFFE
841
841
EMPFEHLEN
-
Hallo zusammen,
ich habe folgendes Problem mit Hibernate:
Ich habe 2 Tabellen ApplicationInfo und ScriptInfo. Diese stehen in einer One-To-Many Beziehung und werden über den Fremdschlüssel ProfileID identifiziert. Deswegen habe ich (über Annotations) folgendes in die Klasse ApplicationInfo.java eingefügt.
Code :1 2 3 4 5 6 7
private Set<ScriptInfo> scriptInfo; ... @OneToMany @JoinColumn(name="ProfileID", referencedColumnName="ProfileID") public Set<ScriptInfo> getScriptInfo() { return scriptInfo; }
Soweit so gut...
Will ich dies dann Testen über
Code :1 2 3 4 5 6 7
session.beginTransaction(); result = session.createSQLQuery("Select * from ApplicationInfo a where a.profileID=1").addEntity(ApplicationInfo.class).list(); session.getTransaction().commit(); System.out.println("Groesse: "+result.size()); //Liefer 1 -> ist richtig ApplicationInfo a = (ApplicationInfo)result.get(0); System.out.println("Leer? :"+a.getScriptInfo().isEmpty());
Wirf er folgenden Fehler: (und zwar genau in der Ausgabe "Leer?"
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [Connector.ApplicationInfo.scriptInfo#1]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2173)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersiste r.java:627)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultIniti alizeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1863)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:3 69)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:134 )
at org.hibernate.collection.PersistentSet.isEmpty(PersistentSet.java:169)
at Connector.TestHibernate.main(TestHibernate.java:45)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'scriptinfo0_.ScriptInfo' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
at org.hibernate.loader.Loader.doQuery(Loader.java:802)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2166)
... 9 more
Ich hab echt keine Ahnung woran das liegt.
Das Durchstöbern diverser Foren hat mich leider auch nicht weiter gebracht. Es wird überall so beschrieben, wie ich es programmiert habe...
Vielen Dank für die Hilfe
-
Moin,
das liegt daran, dass du die Transaktion/Session bereits beendet hast, und die Set "ScriptInfo" nicht initialisiert war. Du vor dem Commit die Set initialisieren: session.initialize(a.getScriptInfo()).
Ähnliche Themen
-
Hibernate Persistence.xml - Sinnvoller Wert für hibernate.hbm2ddl.auto
Von Herr_M im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 3Letzter Beitrag: 08.10.08, 08:21 -
Hibernate: Mapping v. Beziehungen und was Hibernate daraus macht
Von DerGrinsemann im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 2Letzter Beitrag: 14.08.08, 12:53 -
Hibernate: save, update, saveOrUpdate, merge, .... [an alle Hibernate-Profis]
Von DerGrinsemann im Forum JavaAntworten: 2Letzter Beitrag: 13.06.07, 09:24 -
Hibernate 3 Problem
Von mpi im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 1Letzter Beitrag: 13.12.06, 17:24 -
Hibernate (offizielles Eclipse Plugin aus Hibernate Tools) und MySQL
Von webmagier im Forum JavaAntworten: 1Letzter Beitrag: 25.01.06, 17:59





Zitieren
Login





