gpt4 book ai didi

hibernate - 仅 Java EE Hibernate 插入 ?我的 postgresql 数据库中的值

转载 作者:行者123 更新时间:2023-11-29 12:47:38 25 4
gpt4 key购买 nike

我目前正在尝试让 hibernate 状态使用 EJB 将我的 Java EE 实体发送到我的 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;
}

}
<code>
</code>
<code>

<p>and my hibernate.xml file is</p>

</code><pre><code><?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>
</code></pre>

<p>However, after I execute this </p>

<pre> Coup c = new Coup();
c.setJeu("superjeu");
c.setName("supername");
em.persist(c);
</pre>

<p>code, the generated query that I see in the JBOSS6 log is : </p>

14:57:59,364 INFO  [STDOUT] Hibernate: insert into Coup (jeu, name) values (?, ?)

感谢您提供的任何答案。

最佳答案

我认为这只是来自 PreparedStatement 的日志消息,用于显示绑定(bind)参数。

您是否在数据库中查看插入的内容?这是唯一重要的事情,而不是日志。

关于hibernate - 仅 Java EE Hibernate 插入 ?我的 postgresql 数据库中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10897887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com