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.