Reputation: 563
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.
Upvotes: 4
Views: 1090
Reputation: 804
In DataNucleus, this error can also be caused by acting on an entity which is null
, e.g.:
MyEntity entity = txn.em().find(MyEntity.class, entityId); // no such record, returns 'null'
txn.em().lock(entity, LockModeType.OPTIMISTIC_FORCE_INCREMENT); // IllegalArgumentException: Type ("") ...
Upvotes: 0
Reputation: 1936
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 :
<!-- Online Store -->
<persistence-unit name="OnlineStore">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<class>org.datanucleus.samples.metadata.store.Product</class>
<class>org.datanucleus.samples.metadata.store.Book</class>
<class>org.datanucleus.samples.metadata.store.CompactDisc</class>
<class>org.datanucleus.samples.metadata.store.Customer</class>
<class>org.datanucleus.samples.metadata.store.Supplier</class>
<exclude-unlisted-classes/>
<properties>
<property name="datanucleus.ConnectionDriverName" value="org.h2.Driver"/>
<property name="datanucleus.ConnectionURL" value="jdbc:h2:datanucleus"/>
<property name="datanucleus.ConnectionUserName" value="sa"/>
<property name="datanucleus.ConnectionPassword" value=""/>
</properties>
</persistence-unit>
Upvotes: 5