Hallo,
ich hab ein Problem und finde im Netz einfach keine Antworten (vielleicht suche ich auch falsch).
Ich möchte per QueryByExample die Criteria-API nutzen um ein Hibernate-gemapptes Objekt oder Objekte zu suchen. Leider kriege ich nun immer die folgende Exception:
Quote:
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: .Company
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:87)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1707)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1678)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
Hibernate-Version : 3.2.6ga
Mapping:
Quote:
<hibernate-mapping default-lazy="false">
<class name="AccountBalance" table="aTable"
persister="MasterDataLoggingEntityPersister">
<composite-id name="accountBalanceId" class="AccountBalanceId"
access="field">
<key-property name="closingDatePeriodId" type="ClosingDatePeriodID"
access="field">
<column name="ABR_MON_JAHR" length="10" />
</key-property>
<key-property name="companyId" type="CompanyID" access="field">
<column name="GES" length="20" not-null="true" />
</key-property>
</composite-id>
<many-to-one lazy="no-proxy" name="closingDatePeriod"
class="ClosingDatePeriod" insert="false" update="false" access="field"
foreign-key="K003K004">
<column name="ABR_MON_JAHR" length="10" />
</many-to-one>
<many-to-one lazy="no-proxy" name="company" class="Company"
insert="false" update="false" access="field" foreign-key="key">
<column name="GES" length="20" />
</many-to-one>
</class>
</hibernate-mapping>
Code
Quote:
Example example = Example.create(anAccountBalance);
Session commonSession = this.getCommonSession();
Criteria theCriteria = commonSession.createCriteria(anAccountBalance.getClass());
Criteria add = null;
SimpleExpression simpleExpression = (SimpleExpression) iterator.next();
add = theCriteria.add(simpleExpression);
List<T> list = null;
commonSession.flush();
list = add.list();
Thanxs in advance
Christian