I have a strange problem with Hibernate. I can select something from database, but I can't insert or update any value. Here is my configuration and example code, persistance.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="UserDS">
<class>****User</class>
<properties>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/test"/>
<property name="hibernate.connection.username" value="myuser"/>
<property name="hibernate.connection.password" value="mypasword"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
</properties>
</persistence-unit>
</persistence>
entity:
@Entity
@Table(name = "abc", schema = "public")
public class Abc {
@Id
private String aa;
private Integer bb;
public String getAa() {
return aa;
}
public void setAa(String aa) {
this.aa = aa;
}
public Integer getBb() {
return bb;
}
public void setBb(Integer bb) {
this.bb = bb;
}
}
and DAO:
public class TestDOA{
@PersistenceContext(unitName="UserDS")
private EntityManager em;
public String test() {
abc ab = (abc) em.createQuery("FROM abc").getResultList().get(0);
ab.setBb(123);
em.persist(ab);
em.flush();
return ab.getAa() + " " + ab.getBb();
}
When I use test method, I get properly values. In server's log file I can see
[stdout] (default task-7) Hibernate: update public.abc set bb=? where aa=?
but there is no changes in my database. Where is the problem ?