EntityManager.persist(Object)
メソッドの使用に問題があります。他の問題を取り除くと、例外なしでアプリが機能しますが、オブジェクトはデータベースに入れられません。
私のエンティティクラス:
@Entity
@Table(name ="Chain")
public class Chain implements Serializable{
@Id
@Column(name = "id")
private Long id;
@Column(name = "date")
private Date date;
@Column(name = "name")
private String name;
//setters and getters
}
私のdaoクラス:
@Transactional
@Repository("ChainDao")
public class ChainDaoImpl implements ChainDao{
private EntityManager em;
@PersistenceContext
public void setEntityManager(EntityManager em) {
this. em = em;
}
public int saveChain(Chain chain) {
chain.setDate(new Date());
chain.setId((long)44);
Boolean a;
em.persist(chain);
return 222;
}
}
私のxmlコンテキスト:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml"></property></bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
とpereistence.xml
:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="sample">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- Scan for annotated classes and Hibernate mapping XML files -->
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/database"/>
<property name="hibernate.connection.username" value="postgres"/>
<property name="hibernate.connection.password" value="pwd"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
何が欠けているのか誰にも分かりますか?