Hi,
I'm having some problems persisting new objects in my db. I've gotten the update/delete to work flawlessly, but the creation just isn't flying.
I have auto-increment set on the primary key of the table. We're using Embedded Pk's in our entities, and I'm not sure where the @GeneratedValue should go. I've tried on the @Column in the embedded class, next to the @Id, pretty much everywhere. Nothing seems to work.
I keep getting IdentifierGenerationException: ids for this class must be manually assigned before calling save()
Code's below for the Entity, the pk and the simple test
Code:
@Entity
@Table(name = "account_preferences")
public class AccountPreference extends Value<AccountPreferencePk> {
private static final long serialVersionUID = 5433615494763666998L;
/**
* Unique id of this account preference
*/
private AccountPreferencePk pk;
/**
* The type of preference this is
*/
private String preferenceKey;
/**
* String representation of the value of this preference
*/
private String preferenceValue;
/**
* When was the preference last modified
*/
private Date lastModifiedDate;
/**
* User profile that the preference belongs to
*/
private UserProfile userProfile;
public AccountPreference() {
super();
}
public AccountPreference(String key, String value) {
this();
this.preferenceKey = key;
this.preferenceValue = value;
}
public AccountPreference(String key, String value, Date date) {
this(key, value);
this.lastModifiedDate = date;
}
@Id
@Embedded
@GeneratedValue(strategy = GenerationType.AUTO)
public AccountPreferencePk getPk() {
return this.pk;
}
public void setPk(AccountPreferencePk key) {
this.pk = key;
}
Code:
@Embeddable
public class AccountPreferencePk extends PrimaryKeyValue {
private static final long serialVersionUID = 1L;
public long pkValue;
public AccountPreferencePk() {
}
public AccountPreferencePk(long pkValue) {
super(pkValue);
}
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "account_preferences_pk")
public long getPkValue() {
return this.pkValue;
}
public void setPkValue(long pkValue) {
this.pkValue = pkValue;
}
}
And the most basic test ...
Code:
@Test
public void testCRUD() {
AccountPreference pref = new AccountPreference("my_test", "is so cool", new Date());
pref = dao.makePersistent(pref);
assertNotNull(pref.getPk().pkValue);
}
I'm using JBoss 4 w/ EJB3 plugin as our deploy server, and the embeddable ejb3 plugin as our test server.