1
我目前正試圖讓休眠發送我的Java EE實體在我的postgresql數據庫使用EJB。我的實體代碼(用於測試,我用最簡單的一個)是:Java EE Hibernate只能插入?值在我的postgresql數據庫
import java.io.Serializable;
@Entity
public class Coup implements Serializable {
private static final long serialVersionUID = 1L;
@Column(unique=true, nullable=false)
@Id
private String name;
@Column(nullable=false)
private String jeu;
public Coup() {
}
public Coup(String name, String jeu) {
this.name = name;
this.jeu = jeu;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getJeu() {
return this.jeu;
}
public void setJeu(String jeu) {
this.jeu = jeu;
}
}
和我hibernate.xml文件
<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" 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"> <persistence-unit name="PostgresDSjeeux" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/PostgresDSjeeux</jta-data-source> <class>Equipe</class> <class>Joueur</class> <class>Salon</class> <class>Partie</class> <class>HautFait</class> <class>Coup</class> <properties> <!-- <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/> --> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> <property name="hibernate.show_sql" value="true" /> <!-- <property name="transaction.factory_class" value="org.hibernate.transaction.JDBCTransactionFactory" /> --> </properties> </persistence-unit> </persistence>
然而,當我執行此
Coup c = new Coup(); c.setJeu("superjeu"); c.setName("supername"); em.persist(c);
代碼,我在JBOSS6日誌中看到的生成查詢是:
14:57:59,364 INFO [STDOUT] Hibernate: insert into Coup (jeu, name) values (?, ?)
感謝您提供的任何答案。
上帝,我真的覺得很愚蠢。很抱歉提出這個問題,數據是從數據庫開始的,但我認爲它不起作用。我只是安裝了pgadmin3,我的所有數據都在那裏......非常感謝:) – Tuxer
我的榮幸。你是對的... – duffymo
如果你想看到日誌文件中的實際值,你必須使用像log4jdbc這樣的工具 – Johanna