使用Hibernate保存复杂的非hibernate对象

时间:2015-04-19 12:42:54

标签: java hibernate

我正在使用包含此类的基于注释的hibernate ORM设置:

...

@Entity
@Table(name = "characterStates")
public class CharacterState {

    @Getter
    @Setter
    @Column(name = "loc", nullable = false)
    private Location loc;
...
}

Location类是来自库(Sponge)的非hibernate类。当我启动我的插件时,我收到此错误:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_40]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_40]
    at org.spongepowered.mod.plugin.SpongePluginContainer.handleModStateEvent(SpongePluginContainer.java:124) [SpongePluginContainer.class:1.8-1354-1.1DEV-0+unknown-b0.git-unknown]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_40]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_40]
    at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [minecraft_server.1.8.jar:?]
    at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [minecraft_server.1.8.jar:?]
    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [minecraft_server.1.8.jar:?]
    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [minecraft_server.1.8.jar:?]
    at com.google.common.eventbus.EventBus.post(EventBus.java:275) [minecraft_server.1.8.jar:?]
    at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) [LoadController.class:?]
    at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:187) [LoadController.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_40]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_40]
    at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [minecraft_server.1.8.jar:?]
    at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [minecraft_server.1.8.jar:?]
    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [minecraft_server.1.8.jar:?]
    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [minecraft_server.1.8.jar:?]
    at com.google.common.eventbus.EventBus.post(EventBus.java:275) [minecraft_server.1.8.jar:?]
    at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118) [LoadController.class:?]
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:514) [Loader.class:?]
    at net.minecraftforge.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:88) [FMLServerHandler.class:?]
    at net.minecraftforge.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:355) [FMLCommonHandler.class:?]
    at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:117) [po.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:438) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]
Caused by: java.lang.ExceptionInInitializerError
    at ga.copied.api.sponge.CopiedAPISponge.onPreInitialization(CopiedAPISponge.java:64) ~[CopiedAPISponge.class:?]
    ... 32 more
Caused by: org.hibernate.MappingException: Could not determine type for: org.spongepowered.api.world.Location, at table: characterStates, for columns: [org.hibernate.mapping.Column(loc)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) ~[SimpleValue.class:?]
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310) ~[SimpleValue.class:?]
    at org.hibernate.mapping.Property.isValid(Property.java:241) ~[Property.class:?]
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496) ~[PersistentClass.class:?]
    at org.hibernate.mapping.RootClass.validate(RootClass.java:270) ~[RootClass.class:?]
    at org.hibernate.cfg.Configuration.validate(Configuration.java:1360) ~[Configuration.class:?]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851) ~[Configuration.class:?]
    at ga.copied.api.sponge.CopiedAPISponge.onPreInitialization(CopiedAPISponge.java:60) ~[CopiedAPISponge.class:?]
    ... 32 

如何让hibernate使用此类,因为我无法更改位置类。

由于

0 个答案:

没有答案