-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem mit natural-id
PostPosted: Wed Jun 20, 2007 5:07 am 
Newbie

Joined: Thu Jun 07, 2007 10:23 am
Posts: 9
Hallo wenn ich folgendes Mapping

Code:
    <component class="CategoryID" name="id">
      <property name="rootID" type="string" column="ClassID" length="32" unique-key="naturalkey"/>
      <property name="ID" type="string" column="CategID" length="32" not-null="false"  unique-key="naturalkey"/>
    </component>


ändere in

Code:
    <natural-id>
      <component class="CategoryID" name="id">
        <property name="rootID" type="string" column="ClassID" length="32" />
        <property name="ID" type="string" column="CategID" length="32" not-null="false" />
      </component>
    </natural-id>


bekomme ich folgenden Stacktrace:
Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of hibtest.CategoryID.rootID
        at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
        at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:64)
        at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:70)
        at org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:83)
        at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:353)
        at org.hibernate.type.ComponentType.isEqual(ComponentType.java:123)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.checkNaturalId(DefaultFlushEntityEventListener.java:86)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:162)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
        at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
        at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
        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.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
        at $Proxy0.flush(Unknown Source)
        at hibtest.HIBConnection.flushSession(HIBConnection.java:249)
        at hibtest.ClassificationCommands.loadFromFile(ClassificationCommands.java:83)
        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 hibtest.Command.invoke(Command.java:226)
        at hibtest.CommandLineInterface.processCommand(CommandLineInterface.java:239)
        at hibtest.CommandLineInterface.main(CommandLineInterface.java:201)
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@a668fd
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
        ... 27 more


Das einzige, was die beiden Mappings unterscheidet ist, dass ich von einem selbstdefinierten unique-key wechsle auf natural-id. Der Code ändert sich nicht.

Was läuft da falsch? Die Klasse CategoryID entspricht dem natürlichen Schlüssel und wird so von der Anwendung benutzt, deswegen wollte ich es auch so kennzeichnen.

getRootID() ist ein primitive Getter-Methode, die einfach den String zurück gibt. Ich weiß nicht, was diese ClassCastException provoziert.


Top
 Profile  
 
 Post subject: Problem gelöst (Workaround)
PostPosted: Fri Apr 11, 2008 5:30 am 
Newbie

Joined: Thu Jun 07, 2007 10:23 am
Posts: 9
Nachdem ich trotz intensiver Suche nicht zu einer richtigen Lösung gekommen bin, habe ich einen Workaround verwendet.

Code:
    <natural-id>
      <component class="CategoryID" name="id">
        <property name="rootID" type="string" column="ClassID" length="32" />
        <property name="ID" type="string" column="CategID" length="32" not-null="false" />
      </component>
    </natural-id>


habe ich geändert in

Code:
    <natural-id>
        <property name="rootID" type="string" column="ClassID" length="32" />
        <property name="ID" type="string" column="CategID" length="32" not-null="false" />
    </natural-id>


und neue Getter und Setter geschrieben, die das auf Methodenaufrufe von "id" abbilden.


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