Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA Serialization
    primarykey
    data
    text
    <p>I'm working with JPA 2.0-EclipseLink-Hibernate 3 on MySQL 5. My classes structure is like below (I simplified it)</p> <pre><code>public class Status implements Serialization { private String name = null; public Status(string n) { this.name = n; } @Override public String toString() { return this.name; } } @Entity @Table(name="ACCOUNT") public class Account { public static final Status ACTIVE = new Status("AC"); public static final Status DISABLE = new Status("DI"); private Status status = null; private long id = 0; public Account(long id, Status s) { this.id = id; this.status = s; } @Id @Column(name="id") public long getId() { return this.id; } public setId(long id) { this.id = id; } @Column(name="status") public Status getStatus() { return this.status; } public setStatus(Status s) { this.status = s; } } </code></pre> <p>Now, my question is, when I insert a new Account using EntityManager.persist, the program throws an exception: </p> <blockquote> <p>java.sql.SQLException: Incorrect string value: '\xAC\xED\x00\x05sr...' for column 'status' at row 1</p> </blockquote> <p>And after I added a new Account manually into the database, then I select it, the program say:</p> <blockquote> <p>Exception Description: Could not deserialize object from byte array. Internal Exception: java.io.EOFException Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[status-->ACCOUNT.status] Descriptor: RelationalDescriptor(net.serenco.serenekids.model.bean.account.Account --> [DatabaseTable(ACCOUNT)])</p> </blockquote> <p>Please tell me how to control what value will be written to DB, and by the way, please help me fix these errors. Thanks in advance!</p> <p><strong>---------------- EDIT ----------------</strong></p> <p>I have managed to find out the solution myself. It is:</p> <pre><code>@Embeddable public class Status implements Serialization { ... protected String getName() { return name; } protected void setName(String name) { this.name = name; } } @Entity @Table(name="ACCOUNT") public class Account { ... @Embedded @AttributeOverrides( { @AttributeOverride(name="name", column = @Column(name="status") ) } ) public Status getStatus() { return this.status; } ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload