aspose file tools*
The moose likes Object Relational Mapping and the fly likes MappingException Unknown Entity: java.lang.Long with assigned generator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "MappingException Unknown Entity: java.lang.Long with assigned generator" Watch "MappingException Unknown Entity: java.lang.Long with assigned generator" New topic
Author

MappingException Unknown Entity: java.lang.Long with assigned generator

Mark Rucker
Greenhorn

Joined: Aug 17, 2012
Posts: 4
I have a pretty basic Hibernate mapping situation, but I'm unable to save new objects. The error I get when using either session.persist or session.save is org.hibernate.MappingException: Unknown entity: java.lang.Long. Retrieving objects works fine. What am I doing wrong?

Code from main that is throwing the error:



POJO:


Mapping:



Hibernate config file:



The Oracle 11g database table has barcode as the primary key, and it's a string. My User class works fine when saving, but its primary key is a number generated by a sequence, so the mapping file for that class is a little different, in that it uses the sequence generator class.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

Nothing is standing out as amiss to me other than the fact that your test case is

bc.setItemid(14);

and should be

bc.setItemid(14L);

and you are not setting startdate which is not nullable. Those would cause your persist to fail but not I think with the error you are getting. Is your many-to-one bi directional or unidirectional? (does user have a collection of barcode objects) If so what does your User mapping file look like? I just don't see anything wrong with what you have posted from a mapping/configuration standpoint. I suppose for the sake of completeness you could post your schema too, It should be fairly simple based on the mapping I see.


[How To Ask Questions][Read before you PM me]
Mark Rucker
Greenhorn

Joined: Aug 17, 2012
Posts: 4
Yeah, my schema is very simple. Pretty much what you see in the mapping file, except the startdate is populated by a trigger before insert or update, so I leave it out. The User is just as simple. That setup works fine with other Hibernate objects I have when using the sequence generator.

The many-to-one mapping is meant to be unidirectional (user does not have a collection of barcodes), but if you think that could be a cause, I could make it bidirectional.

Unfortunately I can't test your suggestion for the 14L Long value since I'm out of town, but I'll try it when I get a chance.

I was able to get it working by calling session.flush() before creating the new Barcode(), and then session.persist() after assigning the values to the new Barcode(). But that doesn't seem like it should be necessary, and it's not in any Hibernate code I've ever seen.

I'm using Hibernate 4 - could there be a difference from Hibernate 3 in the way things are persisted?

Mark
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

I did not see any issues so I tried running your example and I did not get any exceptions. Test case shown below. I know there are no assertions I just wanted to see if it bombed out with the error you described. I used the same objects you posted. I created the User with a unidirectional relationship. I used the newest version of hibernate. I did use an embedded database not Oracle.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MappingException Unknown Entity: java.lang.Long with assigned generator
 
Similar Threads
CollectionsInHibernate
Resultset.getdate problem...
Simple JPA pogram using EclipseLink
Assigning jsonobject to java class having one to many relationship
Hibernate Select - Criteria with a Date