[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Update corrupt database
fbenvegna
do-not-reply at jboss.com
Thu Aug 30 10:08:34 EDT 2007
I update a EJB Entity and after insert call the record is corrupted...
A value 147.163.0.61 is inserted as 沿47.163.0.61.
The first character is corrupted.
My solution is a persist (with flush) of partial record (with many object attributes insertable=false) and a merge.
I think that problem is many attributes of type java.util.Date. Attributes of type Date are updated but but not inserted.
| @Entity
| @Table(name = "TB_LOG")
| public class Log implements Serializable {
|
| private static final long serialVersionUID = 1L;
|
| @Id
| @Column(name = "OID", updatable = false)
| @SequenceGenerator(name = "SEQUENCE", sequenceName = "SEQ_TB_LOG_WSR", allocationSize = 1)
| @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE")
| private long oid;
|
| @Column(name = "CLI", nullable = false, updatable = false)
| private String clientAddress;
|
| @Lob
| @Basic(fetch=FetchType.LAZY)
| @Column(name = "SOA_REQ", nullable = true, insertable=false)
| private String request;
|
| @Lob
| @Basic(fetch=FetchType.LAZY)
| @Column(name = "SOA_RES", nullable = true, insertable=false)
| private String response;
|
| @Column(name = "DAT", nullable = true, insertable = false)
| private Date date;
|
| ....
| ....
| }
This is the only corrected method to store object Log (others cause curruption)
| Log log = new Log();
| log.setClientAddress(new String(address.toString())); // non so perchè ma necessita ricreare la stringa
| // altrimenti sulla INSERT del db accade un casino
| // !!! BOOOOO
| em.persist(log);
| em.flush();
|
| log.setDate(date); // non so perchè ma non cambiare l'ordine della persist e della merge, altrimenti i dati
| // su db saranno corrotti!!! BOOO
| log.setRequest(request);
| log.setResponse(response);
|
| em.merge(log);
| em.flush();
|
My configuration is:
- JBoss 4.0.5
- Seam 1.2.1.GA
- Hibernate core updated to 3.2.5
- Oracle Database 8.1.7
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4079625#4079625
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4079625
More information about the jboss-user
mailing list