java - Hibernate duplicate key value violates exceptions -


i got exception: duplicate key value violates unique constraint "client_pkey" key (xmppid)=(xyz813@deweet/prototype1006) exists.

my configuration tomcat 6.0, hibernate 3.3.1, c3po 0.9.2 or dbcp.

i don't know how avoid thought making uniqueconstraint , calling in transaction should sole everything.

could tip me doing wrong?

@override @transactional(readonly = false) public client createclient(string userid) {     client c = new client(userid);     currentsession().save(c);     return c; } 

the client class defined below

@entity @table(name = "client", uniqueconstraints = { @uniqueconstraint(columnnames = { "xmppid" }) }) public class client {       @id     private string xmppid;       @override     public boolean equals(object o) {         client c = (client) o;         if (c.xmppid.equals(this.xmppid))             return true;         return false;     }      @override     public int hashcode() {         return this.xmppid.hashcode();     }      ... } 

it doesnt point directly method, $proxy23.createclient think place create , save client.

at $proxy23.createclient(unknown source) @ pl.samsung.cs.deweet.server.requesthandler.onaddvirtualdevice(requesthandler.java:182) @ pl.samsung.cs.deweet.server.requesthandler.handlerequests(requesthandler.java:117) @ pl.samsung.cs.deweet.network.impl.xmppnetcontext$8$1.run(xmppnetcontext.java:518) @ java.lang.thread.run(unknown source)

you don't use auto generated id. means have assign (userid, presumably). when call save attempt insert every time , exception.

depending on you're trying accomplish, may use saveorupdate in place of save.

see reference http://www.javabeat.net/tips/161-difference-between-hibernates-saveupdate-a.html


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -