-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem mit queryByExample und Associations
PostPosted: Wed Jun 13, 2007 12:46 am 
Newbie

Joined: Wed Dec 13, 2006 8:18 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.4

Mapping documents:
Code:
<class name="com.mvb.uwdb.beans.orga.Diktatzeichen" table="DIKTATZEICHEN">
   <meta attribute="dataTablespace">organisation</meta>   
   <meta attribute="indexTablespace">xorganisation</meta>   
   <meta attribute="protocol">yes</meta>
   <id name="id" column="ID" type="long">
      <generator class="native"></generator>
   </id>
   <property name="dz" column="DZ" type="string" length="5" unique-key="uxDZ01" not-null="true"></property>
   <many-to-one name="mandant" lazy="proxy" column="MANDANT" class="com.mvb.uwdb.beans.orga.Mandant" unique-key="uxDZ01" foreign-key="fkDZ01" not-null="true"></many-to-one>
   <property name="geaendert_durch" type="string" length="128">
      <column name="GEAENDERT_DURCH" default="USER" length="128" not-null="true"></column>
   </property>
   <property name="geaendert_am" type="calendar"  not-null="true" >
      <column name="GEAENDERT_AM" default="CURRENT TIMESTAMP" ></column>
   </property>
</class>

<class name="com.mvb.uwdb.beans.orga.Mandant" table="MANDANT" >
   <meta attribute="dataTablespace">organisation</meta>   
   <meta attribute="indexTablespace">xorganisation</meta>   
   <meta attribute="protocol">yes</meta>
   <id name="id" column="ID" type="long">
      <generator class="native"></generator>
   </id>
   <property name="rzbk" column="RZBK" type="big_decimal" precision="4" scale="0" unique-key="uxMANDANT01" not-null="true"></property>
   <property name="bezeichnung" column="BEZEICHNUNG" type="string" length="75" unique-key="uxMANDANT02" not-null="true"></property>
   <property name="kurzbez" column="KURZBEZ" type="string" length="5"></property>
   <property name="geaendert_durch" type="string" length="128">
      <column name="GEAENDERT_DURCH" default="USER" length="128" not-null="true"></column>
   </property>
   <property name="geaendert_am" type="calendar"  not-null="true" >
      <column name="GEAENDERT_AM" default="CURRENT TIMESTAMP" ></column>
   </property>
      <set name="ycprefixe" lazy="true" cascade="all-delete-orphan" sort="natural" batch-size="50" inverse="true">
      <key column="mandant" on-delete="cascade"></key>
      <one-to-many class="com.mvb.uwdb.beans.orga.YCPrefix"/>
   </set>
</class>

<class name="com.mvb.uwdb.beans.orga.Mitarbeiter" table="MITARBEITER">
   <meta attribute="dataTablespace">organisation</meta>   
   <meta attribute="indexTablespace">xorganisation</meta>   
   <meta attribute="protocol">yes</meta>
   <id name="id" column="ID" type="long">
      <generator class="identity"></generator>
   </id>
   <property name="personalnr" column="PERONALNR" type="integer" unique-key="uxMITARBEITER01" not-null="true"></property>
   <property name="name" column="NAME" type="string" length="50" not-null="true"></property>
   <property name="vorname" column="VORNAME" type="string" length="50" not-null="true"></property>
      <many-to-one name="anrede" column="ANREDE" class="com.mvb.uwdb.beans.key.Anrede" foreign-key="fkMITARBEITER01"></many-to-one>
   <many-to-one name="titel" column="TITEL" class="com.mvb.uwdb.beans.key.Titel" foreign-key="fkMITARBEITER02"></many-to-one>
   <many-to-one name="diktatzeichen" column="DIKTATZEICHEN" class="com.mvb.uwdb.beans.orga.Diktatzeichen" cascade="all" unique="true" foreign-key="fkMITARBEITER03"></many-to-one>
   <many-to-one name="ycnr" column="YCNR" class="com.mvb.uwdb.beans.orga.YCNr"  cascade="all" unique="true" foreign-key="fkMITARBEITER04"></many-to-one>
   <property name="passwort" column="PASSWORT" type="string" length="32"></property>
   <property name="authcode" column="AUTHCODE" type="string" length="50"></property>
   <property name="aufgabe" column="AUFGABE" type="string" length="50"></property>
   <property name="geaendert_durch" type="string" length="128">
      <column name="GEAENDERT_DURCH" default="USER" length="128" not-null="true"></column>
   </property>
   <property name="geaendert_am" type="calendar"  not-null="true" >
      <column name="GEAENDERT_AM" default="CURRENT TIMESTAMP" ></column>
   </property>
      <bag name="funktionen" schema="ORGA" table="MITARB2FUNK">
      <key column="MITARBEITER" on-delete="noaction"></key>
      <many-to-many column="FUNKTION" class="com.mvb.uwdb.beans.orga.Funktion"/>
   </bag>
   <bag name="roles" schema="ORGA" table="USER2ROLE" order-by="ORDER ASC">
      <key column="MITARBEITER" on-delete="noaction"></key>
      <many-to-many column="ROLE" class="com.mvb.uwdb.beans.orga.Role"/>
   </bag>
       <bag name="berater" schema="ORGA" table="BERATER" cascade="all" inverse="true" order-by="NUMMER ASC">
      <key column="mitarbeiter" on-delete="noaction"></key>
      <one-to-many class="com.mvb.uwdb.beans.orga.Berater"/>
   </bag>
      <set name="kontakte" cascade="all" sort="natural" inverse="true">
      <key column="mitarbeiter" on-delete="noaction"></key>
      <one-to-many class="com.mvb.uwdb.beans.orga.MAKontakt"/>
   </set> 
</class>

<class name="com.mvb.uwdb.beans.orga.YCNr" table="YCNR">
   <meta attribute="dataTablespace">organisation</meta>   
   <meta attribute="indexTablespace">xorganisation</meta>   
   <meta attribute="protocol">yes</meta>
      <id name="id" column="ID" type="long">
      <generator class="native"></generator>
   </id>
   <property name="kennzeichen" column="KENNZEICHEN" type="string" length="5" unique-key="uxYCNR01" not-null="true"></property>
   <many-to-one name="prefix" column="YCPREFIX" class="com.mvb.uwdb.beans.orga.YCPrefix" cascade="all" unique-key="uxYCNR01" foreign-key="fkYCNR01"></many-to-one>
   <property name="geaendert_durch" type="string" length="128">
      <column name="GEAENDERT_DURCH" default="USER" length="128" not-null="true"></column>
   </property>
   <property name="geaendert_am" type="calendar"  not-null="true" >
      <column name="GEAENDERT_AM" default="CURRENT TIMESTAMP" ></column>
   </property>
</class>

<class name="com.mvb.uwdb.beans.orga.YCPrefix" table="YCPREFIX">
   <meta attribute="dataTablespace">organisation</meta>   
   <meta attribute="indexTablespace">xorganisation</meta>   
   <meta attribute="protocol">yes</meta>
   <id name="id" column="ID" type="long">
      <generator class="native"></generator>
   </id>
   <property name="bezeichnung" column="BEZEICHNUNG" type="string" length="10" unique-key="uxYCPREFIX01" not-null="true"></property>
   <property name="kurzbez" column="KURZBEZ" type="string" length="5"></property>
   <many-to-one lazy="proxy" name="mandant" column="MANDANT" class="com.mvb.uwdb.beans.orga.Mandant" cascade="all" foreign-key="fkYCPREFIX01" not-null="true"></many-to-one>
   <property name="geaendert_durch" type="string" length="128">
      <column name="GEAENDERT_DURCH" default="USER" length="128" not-null="true"></column>
   </property>
   <property name="geaendert_am" type="calendar"  not-null="true" >
      <column name="GEAENDERT_AM" default="CURRENT TIMESTAMP" ></column>
   </property>
</class>



Full stack trace of any exception that occurs:
Code:
06:42:41,291 ERROR RecordDAO:275 - object references an unsaved transient instance - save the transient instance before flushing: com.mvb.uwdb.beans.orga.Diktatzeichen
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.mvb.uwdb.beans.orga.Diktatzeichen
   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:88)
   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:2220)
   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)
   at com.mvb.dao.RecordDAO.findByExample(RecordDAO.java:271)
   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.mozilla.javascript.MemberBox.invoke(MemberBox.java:145)
   at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:204)
   at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3085)
   at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2251)
   at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:161)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:340)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2758)
   at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:159)
   at org.mozilla.javascript.Context.call(Context.java:489)
   at org.mozilla.javascript.ScriptableObject.callMethod(ScriptableObject.java:1556)
   at org.mozilla.javascript.ScriptableObject.callMethod(ScriptableObject.java:1526)
   at org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter.handleContinuation(FOM_JavaScriptInterpreter.java:839)
   at org.apache.cocoon.components.treeprocessor.sitemap.CallFunctionNode.invoke(CallFunctionNode.java:124)
   at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:47)
   at org.apache.cocoon.components.treeprocessor.sitemap.MatchNode.invoke(MatchNode.java:108)
   at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:69)
   at org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(PipelineNode.java:143)
   at org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:69)
   at org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(PipelinesNode.java:93)
   at org.apache.cocoon.components.treeprocessor.ConcreteTreeProcessor.process(ConcreteTreeProcessor.java:235)
   at org.apache.cocoon.components.treeprocessor.ConcreteTreeProcessor.process(ConcreteTreeProcessor.java:177)
   at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:253)
   at org.apache.cocoon.Cocoon.process(Cocoon.java:699)
   at org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1154)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at com.mvb.hibernate.util.HibernateFilter.doFilter(HibernateFilter.java:45)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
   at java.lang.Thread.run(Thread.java:619)


Name and version of the database you are using:
IBM DB2 UDB V8.1.2

The generated SQL (show_sql=true):
Code:
select this_.ID as ID9_0_, this_.PERONALNR as PERONALNR9_0_, this_.NAME as NAME9_0_, this_.VORNAME as VORNAME9_0_, this_.ANREDE as ANREDE9_0_, this_.TITEL as TITEL9_0_, this_.DIKTATZEICHEN as DIKTATZE7_9_0_, this_.YCNR as YCNR9_0_, this_.PASSWORT as PASSWORT9_0_, this_.AUTHCODE as AUTHCODE9_0_, this_.AUFGABE as AUFGABE9_0_, this_.GEAENDERT_DURCH as GEAENDERT12_9_0_, this_.GEAENDERT_AM as GEAENDERT13_9_0_ from ORGA.MITARBEITER this_ where (this_.DIKTATZEICHEN=? and this_.YCNR=?)


Zunächst: Ich weiß, dass es ein nicht ganz neues Problem ist und ich habe mich nun schon seit Wochen mit Suchen beschäftigt.

Ich benötige innerhalb einer Webanwendung die Möglichkeit Mitarbeiter zu suchen.
Hierfür können beliebig viele Daten als Filter angegeben werden.
Diese Daten werden nach Absenden des Formulares in einem Bean gespeichert, welches dann für ein QueryByExample übergeben wird.

Solange ich für die Suche nur Properties wie Name, Vorname etc. verwende reicht hier ja das "normale" Example aus. Associations, wie z.B. das Diktatzeichen oder die YCNr werden aber hier komplett ignoriert.

Zur Lösung dieses Problems habe ich dann diese AssociationExample-Klasse herangezogen.

Leider wird aber nun hier die o.g. Exception geworfen.
Mache ich hier irgendwo einen grundsätzlichen Denkfehler?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 7:35 am 
Regular
Regular

Joined: Thu Jan 27, 2005 8:58 am
Posts: 80
Mach es Dir doch nichts so schwer und schreib einfach ein HQL!
Ich bin zeimlich schnell von den Abfragen mit Criterias auf HQL umgestiegen, weil es wesentlich einfacher ist und oft auch schneller.

An für sich bkomme ich die Fehlermeldung die Du dort gepostet hast nur dann, wenn ich ein transientes Hibernate-Objekt mit weiteren transienten Assoziationsobjekten befülle und speichern möchte.
In diesem Fall müssen die Assoziationsobjekte vor dem eigentlichen Objekt gespeichert werden, damit Hibernate die Id für den FK zur Verfügung hat.

Aber es tauchen auch noch ein paar Fragen auf:
• Kann es sein, dass Dein Diktatzeichen keinen Wert für die PK enthält?
• Wird die Abfrage innerhalb einer Transaction mit abschliessendem commit durchgeführt?

Wenn ja zu Frage 2: Ich könnte mir vorstellen, dass Hibernate zum Schluss durch das commit versucht Dein Abfrageobjekt zu persistieren. Es klappt aber aufgrund des oben genannten Beispiels nicht.

_________________
Weise ist nicht, wer viele Erfahrungen macht, sondern wer aus wenigen lernt, viele nicht machen zu müssen. (Karlheinz Deschner)


Top
 Profile  
 
 Post subject: Re: Problem mit queryByExample und Associations
PostPosted: Wed Dec 10, 2008 9:14 am 
Newbie

Joined: Mon May 19, 2008 9:27 am
Posts: 8
Hallo Michael,

hast du noch weitere Antworten auf diese Frage gefunden? Oder jemand anderes.

Knapp 2 Jahre nach deiner Mail habe ich das gleiche Problem?

Gruß Christian


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