Hello,
 
I am attempting to create a new entry in my database (MySQL 1.4) using  the following lines of code. The Objects UserProfile and Resource have been queried earlier and are valid objects.
 
...
UserProfile up;
Resource r;
Subscription s = new Subscription(up, r, null)
 
try {
    db.begin();
    db.create(s);
    db.commit();
} catch (PersistenceException pex) {
    pex.printStackTrace();
}
 
This all seems simple enough but it throws an exception:
 
java.sql.SQLException: General error, message from server: "Column 'user_profile_id' cannot be null"
at com.mysql.jdbc.MysqlIO.checkErrorPacket...
....
 
I have identified the problem but don't know why it occurs or how to overcome it. In the mapping file I have defined the UserProfile object with a key-generator:
 
<mapping>
    <class name="UserProfile" identity="id" key-generator="IDENTITY">
.....
 
When I remove this attribute (key-generator="IDENTITY") from the mapping file it all works fine and inserts the new Subscription as I would like but it is vital to have the key generation at other points. Any help on this matter would be greatly appreciated.
 
Alex

Reply via email to