generated id to be copied in anothre column as string upon creation
This is a JavaEE6 application using Hibernate and PostgreSQL. Users are created in the database with @GeneratedValue(strategy = GenerationType.AUTO)
that generates Long ids. I am trying to use the user_id column of the database as the name column for the login realm ( e.g request.login(id.toString(), password )
) because I can not ensure uniqueness of the names in the user_name 开发者_如何学Ccolumn. However, using the built-in FORM authentication with Glassfishv3, it fails as it seems that the mechanism expect the column in the database to be a var char.
Thanks.
You can do it in one shot -
@Entity
public class A {
@Id @GeneratedValue(strategy=SEQUENCE)
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
private Integer id;
public String getName() { return name; }
private void setName(String name) { this.name = name; }
private String name;
}
Serializable id = em.unwrap(Session.class).save(a);
a.setName("Why oh why redundancy? " + id);
em.flush();
Code copied from https://gist.github.com/786238
精彩评论