GAE/J - JPA 错误 - 类型(“”)不是实体的类型,但需要用于此操作
我对 JPA 不太熟悉,但我做了一些搜索,但找不到这个错误代码,所以我将其发布在这里。
我正在尝试保留此类:
@Entity(name = "UserBasket")
public class UserBasket extends BaseBasket implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long Id;
private static final long serialVersionUID = 1L;
public static long getSerialversionuid() {
return serialVersionUID;
}
public Long getId() {
return Id;
}
public void setId(Long id) {
Id = id;
}
}
使用此方法调用:
public Long createUserBasket(UserBasket basket) {
try{
synchronized (this) {
EntityManager em = EMFService.get().createEntityManager();
em.persist(basket);
em.close();
}
}catch(Exception ex){
//log.severe("Uh oh!" + ex.toString());
}
}
并收到此错误:
java.lang.IllegalArgumentException: Type ("") is not that of an entity but needs to be for this operation
我在 GAE 上运行此代码。我怀疑这与我的实体有关,但我不确定是什么。
编辑:填写更多详细信息 -
这是 BaseBasket (我删除了 getter 和 setter)
@Entity(name = "BaseBasket")
public class BaseBasket {
public String basketID;
public List<BasketItem> items;
}
我用一个简单的方法创建了 UserBasket:
UserBaset b = new UserBasket();
然后分配各种值。
我没有使用 datanucleus 增强器,这只是我天真的理解,它不是必需的,并且由于这些对象(UserBasket 等)在我的应用程序的客户端和服务器部分之间共享,我想让它们保持简单。
I'm a little green with JPA but I did some searching and couldn't find this error code so I'll post it here.
I'm trying to persist this class:
@Entity(name = "UserBasket")
public class UserBasket extends BaseBasket implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long Id;
private static final long serialVersionUID = 1L;
public static long getSerialversionuid() {
return serialVersionUID;
}
public Long getId() {
return Id;
}
public void setId(Long id) {
Id = id;
}
}
With this method call:
public Long createUserBasket(UserBasket basket) {
try{
synchronized (this) {
EntityManager em = EMFService.get().createEntityManager();
em.persist(basket);
em.close();
}
}catch(Exception ex){
//log.severe("Uh oh!" + ex.toString());
}
}
And getting this Error:
java.lang.IllegalArgumentException: Type ("") is not that of an entity but needs to be for this operation
I'm running this on GAE. I suspect it's something to do with my Entity but I'm not sure what.
Edit: Filling in more details -
Here is BaseBasket (I cut out the getters and setters)
@Entity(name = "BaseBasket")
public class BaseBasket {
public String basketID;
public List<BasketItem> items;
}
And I create the UserBasket with a simple:
UserBaset b = new UserBasket();
And then assign the various values.
I didn't use the datanucleus enhancer as, and this is only my naive understanding, that it isn't required and as these objects (UserBasket etc) are shared between the client and server part of my application I wanted to keep them simple.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您使用的是 JPA,请检查 persistence.xml 定义是否符合 DataNucleus 文档
特别是,如果您不使用映射文件,请检查您想要保留的所有实体是否已在类元素中声明。作为提供的示例:
Since you're using JPA, check that your persistence.xml definition is conform to the DataNucleus documentation
In particular, if you're not using a mapping file, check that all your entities you want to persist are declared in classes elements. As the provided example :
在DataNucleus中,此错误也可能是由于作用于
null
的实体而引起的,例如:In DataNucleus, this error can also be caused by acting on an entity which is
null
, e.g.: