我想从Ebean持久性中排除items
。
这是我的豆子:
package entity;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.avaje.ebean.validation.Length;
import com.avaje.ebean.validation.NotNull;
@Entity()
@Table(name="profile")
public class Profile {
private Item[] items;
@Transient
public Item[] getItems() {
return items;
}
public void setItems(Item[] items) {
this.items = items;
}
@Id
private int id;
@Length(max=50)
@NotNull
private String externalReference;
...
但我得到以下堆栈跟踪:
[20:16:18] [Server thread/ERROR]: Was unable to use reflection to find a constructor and appropriate getters forimmutable type class [Lentity.Item;. The errors while looking for the getter methods follow:
[20:16:18] [Server thread/ERROR]: Error with entity.Profile field:items
java.lang.RuntimeException: Unable to use reflection to build ImmutableMeta for class [Lentity.Item;. Associated Errors trying to find a constructor and getter methods have been logged
at com.avaje.ebeaninternal.server.type.reflect.ImmutableMetaFactory.createImmutableMeta(ImmutableMetaFactory.java:71) ~[craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.type.DefaultTypeManager.recursiveCreateScalarTypes(DefaultTypeManager.java:224) ~[craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.createProp(DeployCreateProperties.java:367) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.createProp(DeployCreateProperties.java:387) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.createProperties(DeployCreateProperties.java:168) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.parse.DeployCreateProperties.createProperties(DeployCreateProperties.java:94) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.createDeployBeanInfo(BeanDescriptorManager.java:1041) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readEntityDeploymentInitial(BeanDescriptorManager.java:552) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.deploy(BeanDescriptorManager.java:269) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.core.InternalConfiguration.<init>(InternalConfiguration.java:143) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:209) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:63) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:78) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.java.JavaPlugin.init(JavaPlugin.java:344) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:104) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:67) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at profile.ProfilePlugin.<init>(ProfilePlugin.java:16) [crm-profile.jar:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [?:1.7.0_45]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [?:1.7.0_45]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:1.7.0_45]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [?:1.7.0_45]
at java.lang.Class.newInstance(Class.java:374) [?:1.7.0_45]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.craftbukkit.v1_10_R1.CraftServer.loadPlugins(CraftServer.java:294) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.craftbukkit.v1_10_R1.CraftServer.reload(CraftServer.java:723) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.Bukkit.reload(Bukkit.java:548) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchCommand(CraftServer.java:625) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.PlayerConnection.handleCommand(PlayerConnection.java:1299) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1159) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [?:1.7.0_45]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_45]
at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:690) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:646) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:550) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at java.lang.Thread.run(Thread.java:744) [?:1.7.0_45]
[20:16:18] [Server thread/ERROR]: Error in deployment
javax.persistence.PersistenceException: Error with [entity.Profile] I believe it is not enhanced but it's superClass [class java.lang.Object] is? (You are not allowed to mix enhancement in a single inheritance hierarchy)
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.setBeanReflect(BeanDescriptorManager.java:1393) ~[craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.createByteCode(BeanDescriptorManager.java:1161) ~[craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readDeployAssociations(BeanDescriptorManager.java:1077) ~[craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readEntityDeploymentAssociations(BeanDescriptorManager.java:584) ~[craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.deploy(BeanDescriptorManager.java:271) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.core.InternalConfiguration.<init>(InternalConfiguration.java:143) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:209) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:63) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:78) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.java.JavaPlugin.init(JavaPlugin.java:344) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:104) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:67) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at profile.ProfilePlugin.<init>(ProfilePlugin.java:16) [crm-profile.jar:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [?:1.7.0_45]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [?:1.7.0_45]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:1.7.0_45]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [?:1.7.0_45]
at java.lang.Class.newInstance(Class.java:374) [?:1.7.0_45]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.craftbukkit.v1_10_R1.CraftServer.loadPlugins(CraftServer.java:294) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.craftbukkit.v1_10_R1.CraftServer.reload(CraftServer.java:723) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.Bukkit.reload(Bukkit.java:548) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchCommand(CraftServer.java:625) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.PlayerConnection.handleCommand(PlayerConnection.java:1299) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1159) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [?:1.7.0_45]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_45]
at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:690) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:646) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:550) [craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at java.lang.Thread.run(Thread.java:744) [?:1.7.0_45]
Caused by: java.lang.IllegalArgumentException: field [items] not found in [entity.Profile$$EntityBean$crm-profile][id, externalReference, playerId, location, clan, playerClass, visible, deleted, health, level, pvpKills, pvpDeaths, mobKills, mobDeaths, onlineDuration, durationSinceLastDeath, lastUpdated, lastDeathDurationCheck]
at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflect.getFieldIndex(EnhanceBeanReflect.java:139) ~[craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflect.getGetter(EnhanceBeanReflect.java:143) ~[craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.setBeanReflect(BeanDescriptorManager.java:1377) ~[craftbukkit-1.10.2.jar:git-Bukkit-0ebb9c7]
... 40 more
有人可以告诉我如何正确地将成员变量items
声明为@Transient
,以便将其从持久性中排除?
答案 0 :(得分:0)
要解决此问题,您需要将@Transient
注释应用于字段items
(而不是getItems()
),如下所示:
@Entity()
@Table(name="profile")
public class Profile {
@Id
private int id;
@Transient
private Item[] items;
public Item[] getItems() {
return items;
}
...
}
P.S。:如果您有@Transient
个字段,请确保将JPA注释始终放在getter方法或字段上,而不是在两个地方分发。在您当前的代码中,其他JPA注释(例如@Id
)已标记为除@Transient
以外的字段。
它可以解决这个问题,但是我在JPA规范或Hibernate上找不到任何东西。
答案 1 :(得分:0)
这是4.0.1之前的EBean版本中的错误。解决方法是:
将属性更改为List或Set而不是数组。
- 醇>
如果可能的话,也标记“瞬态”字段,即如果您不需要在字段上使用Java序列化。
如相关bug report中所述。