Hi, I have a bi-directional multivalued relation between classes com.test.A, com.test.B (A has n B), and the classes com.test.SpecialA and com.test.SpecialB extend A, B respectively. Beside that they override the relation between A and B. Note that in both classes B and SpecialB there are fields of name a$order and type integer to be used as orderBy field for the collection. here part of code:
the getter of B in class A:
@OneToMany(targetEntity=com.test.SpecialB.class, cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="a",orphanRemoval=true) @OrderBy(value="a$order") public List<com.test.B> getB(){...}
the getter of B in SpecialA:
@OneToMany(targetEntity=com.test.B.class, cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="a",orphanRemoval=true) @OrderBy(value="a$order") public List<com.test.B> getB(){...}
Now, when trying to execute JPA query to find SpecialA elements I got the following exception: Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Exception occurred inside setter of com.test.SpecialA.b at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1235) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1168) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:250) at com.Tester.main(Tester.java:47) Caused by: org.hibernate.PropertyAccessException: Exception occurred inside setter of com.test.SpecialA.b at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:89) at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:586) at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:231) at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3824) at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:153) at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:898) at org.hibernate.loader.Loader.doQuery(Loader.java:773) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270) at org.hibernate.loader.Loader.doList(Loader.java:2294) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172) at org.hibernate.loader.Loader.list(Loader.java:2167) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:241) ... 1 more Caused by: java.lang.reflect.InvocationTargetException 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:597) at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:66) ... 17 more Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.test.SpecialA.b#component[id]{id=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:2069) at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62) at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:628) at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83) at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1853) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108) at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:272) at com.palmyra.arch.basicStruct.data.CollectionHelper.iterator(CollectionHelper.java:245) at com.palmyra.arch.basicStruct.data.CompositeValue.updateSymmetricRole(CompositeValue.java:1149) at com.palmyra.arch.basicStruct.data.CompositeValue.setSimple(CompositeValue.java:959) at com.test.SpecialA.setB(SpecialA.java:94) ... 22 more Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'b0_.test_B.a$order_' in 'order clause' at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723) at com.mysql.jdbc.Connection.execSQL(Connection.java:3283) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1467) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1849) at org.hibernate.loader.Loader.doQuery(Loader.java:718) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270) at org.hibernate.loader.Loader.loadCollection(Loader.java:2062) ... 33 more DEBUG main org.hibernate.util.JDBCExceptionReporter - could not initialize a collection: [com.test.SpecialA.b#component[id]{id=1}] [select b0_.a_id_ as a3_0_1_, b0_.id_ as id2_1_, b0_.id_ as id1_2_0_, b0_1_.a_id_ as a9_2_0_, b0_1_.a$order_ as a2_2_0_, b0_1_.creationDate_ as creation3_2_0_, b0_1_.creatorUserId_ as creatorU4_2_0_, b0_1_.type_ as type5_2_0_, b0_1_.updateDate_ as updateDate6_2_0_, b0_1_.updatorUserId_ as updatorU7_2_0_, b0_1_.version_ as version8_2_0_, b0_.a_id_ as a3_3_0_, b0_.a$order_ as a1_3_0_ from test_SpecialB b0_ inner join test_B b0_1_ on b0_.id_=b0_1_.id_ where b0_.a_id_=? order by b0_.test_B.a$order_ asc]
|