Hi, Kind of strange. OpenJPA has many, many examples of persistent operations against various databases, including MySQL. All without the behavior that you are seeing. A couple of things jump out at me...
o How is your dao constructor setting the values on the fields? Since you are using property-based access, all access to these fields need to be through the getter/setter methods. o I noticed that your getter/setter methods are "synchronized final". OpenJPA states support for "final" methods, so that should work okay. But, why are you using synchronized? I don't see why this should make a difference, but it's overhead that should not be necessary. o And, when is the transaction completing? The em.persist() method does not push items to the database. The enclosing transaction needs to complete, or a flush needs to happen, to push the data to the database. o How are you verifying that the records are getting created? You see actual records (rows) getting created with new generated IDs, but none of the other fields are filled in? You could turn on SQL trace from OpenJPA and see what SQL is actually being generated. This would help confirm whether the problem is in the application space or the database space. Let's start with these questions before going further. Thanks, Kevin On Fri, Dec 4, 2009 at 9:32 AM, kpsuk <[email protected]> wrote: > > Having a little trouble with openJPA persiting with MySQL, whilst new rows > are being created for each em.persist(dao) the rows are bring populated > with > 'NULL' values for each column! > > I get no error in my logs and debugging shows that the property values are > there right upto the em.persist(dao) line of code. > > DAO > @Entity > @Table(name = "tbl_user_details") > public class UserRegistrationDao implements java.io.Serializable { > private int id; > private String firstname; > private String surname; > private String email; > @Id > @GeneratedValue(strategy = GenerationType.IDENTITY) > @Column(name="id") > public int getId() { > return this.id; > } > public void setId(int id) { > this.id = id; > } > > @Basic > @Column(name="firstname") > public synchronized final String getFirstname() { > return this.firstname; > } > public synchronized final void setFirstname(String firstname) { > this.firstname = firstname; > } > > @Basic > @Column(name="surname") > public synchronized final String getSurname() { > return this.surname; > } > public synchronized final void setSurname(String surname) { > this.surname = surname; > } > > @Basic > @Column(name="email") > public synchronized final String getEmail() { > return this.email; > } > public synchronized final void setEmail(String email) { > this.email = email; > } > } > > Bean > @PersistenceContext(unitName = "users", type = > PersistenceContextType.EXTENDED) > private EntityManager _em; > @Override > public boolean create(Map<String, Object> args) { > UserRegistrationDao dao = new UserRegistrationDao(args); > _em.persist(dao); // *** upto here values are present *** > > > persistence.xml > > <persistence-unit name="users" transaction-type="JTA"> > > <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> > <jta-data-source>jdbc/users</jta-data-source> > <!-- Enumerate your persistent classes here. --> > <class>com.project1.business.dao.UserRegistrationDao</class> > > <properties> > <property name="openjpa.ConnectionURL" > value="jdbc:mysql://localhost:3306/users"/> > <property name="openjpa.ConnectionDriverName" > value="com.mysql.jdbc.Driver"/> > <property name="openjpa.ConnectionUserName" > value="root"/> > <property name="openjpa.ConnectionPassword" > value="rootpass123"/> > </properties> > > </persistence-unit> > > -- > View this message in context: > http://n2.nabble.com/openJPA-with-EJB3-MySQL-on-WAS7-tp4113103p4113103.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. >
