Hi, I'm getting this error-meassage:
Quote:
ids for this class must be manually assigned before calling save()
Cause the public contrutor is forcing the id, I can't see anything wrong.
Here is the code:
Code:
@Entity
public class VitaxDatabaseUser implements Serializable {
/**
* Encrypts the given String.
*
* @param plainText
* the string to be encrypted
* @return encrypted String
*/
private static String encrypt(String plainText) {
.....
}
/** The name of the user. */
@Id
private String name;
/** The role of the given user */
@Enumerated(value = EnumType.STRING)
private DefinedRoles role;
/** The password of the user */
/* Encrypzted kann es evtl. auch länger als 255 Zeichen sein, daher @Lob */
@Lob
private String pass;
/** For Hibernate only */
@SuppressWarnings("unused")
private VitaxDatabaseUser() {
}
public VitaxDatabaseUser(final String name, final DefinedRoles role, final String pass) {
this.name = name;
this.role = role;
this.pass = encrypt(pass);
}
public String getName() {
return this.name;
}
/**
*
* @return the encrypted password!
*/
public String getPass() {
return this.pass;
}
public DefinedRoles getRole() {
return this.role;
}
/**
* Compares an entered passwort with the stored one.
*
* @param plainPass
* @return
*/
public boolean passEquals(final String plainPass) {
return this.pass.equals(encrypt(plainPass));
}
}
Code:
final VitaxDatabaseUser user = new VitaxDatabaseUser(this.userNameTF.getName(),
(DefinedRoles) this.levelCB.getSelectedItem(), userPassword);
final Session s = HibernateUtil.getSession();
final Transaction tx = s.beginTransaction();
try {
s.save(user);
tx.commit();
}
....
this.userNameTF.getName() is not null!
What is my mistake?
Thanks a lot in advance.
Greetings Michael