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:
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.
Nothing is standing out as amiss to me other than the fact that your test case is
and should be
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.
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?
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.