I know this is strange, but hey ...
I'm parsing out some user information from an XML feed. The only key I have to work with is the value of the email.
Therefore, my db is setup to have the email as a primary key.
I've used Hibernate on a couple simple projects up to now (this one being one of them), but I've always had ID's to work with. It's the first time I have a string key to work with that isn't autogenerated, and it's not working out at all.
Mapping file looks something like:
<class name="clas" table="table">
<id name="Email" type="string">
<column name="email" unique="true" length="250" not-null="true"/>
<generator class="assigned"/>
</id>
<property name="status" type="boolean">
<column name="status" length="50" not-null="true"/>
</property>
......
</class>
And I've got some simple code to do the insert/update:
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
session.saveOrUpdate(profile);
tx.commit();
HibernateUtil.closeSession();
The error I get when a row does not exist in the database (therefore, when it's time to do an update) is:
There was a fatal exception:net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
I tried to get around it by doing a session.get() first, but my key is a String , hence not Serializable, so I'm not sure how to do it.
Any help for this embarassingly stupid problem of mine would be appreciated.
(I'm using the latest version of Hibernate)
Thanks.
|