I there !
I got some problems with hbm2ddl tool.. I tried all modes (create, update, ...) and each time, my tables and primary keys are correctly created but no one foreign key !
And no errors are printed in hibernate log... Is there a property anywhere in configuration file to set to enable foreign keys creation ? What is I'm doing wrong ?
I'm using Hibernate annotations and Hibernate EntityManager under JBOSS 4, with PostrgreSQL 8.2.
Here is my datasource conf :
Code:
<datasources>
<local-tx-datasource>
<jndi-name>PostgresqlTest</jndi-name>
<connection-url>jdbc:postgresql://127.0.0.1:5432/testdb</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>ogp</user-name>
<password>ogpogp</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
</local-tx-datasource>
</datasources>
And hibernate conf (persistence.xml)
Code:
<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="hibernateEM" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/PostgresqlTest</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.ProgressDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
My entities (without getters/setters which are of no importance here)
DbTestMessage.java :
Code:
@Entity
@Table(name = "test_message")
@javax.persistence.TableGenerator(name="DbTestMessage_GEN",
table="id_sequence",
pkColumnName = "entity_name",
valueColumnName = "value",
pkColumnValue="DbTestMessage",
allocationSize=20)
public class DbTestMessage implements Serializable {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy = GenerationType.TABLE, generator="DbTestMessage_GEN")
private Integer id;
@Column(nullable = false, unique = false, name = "date")
private Date date;
@ManyToOne(optional = false)
@JoinColumn(nullable = false, unique = false, name = "topic")
private DbTestTopic topic;
@Column(nullable = false, unique = false, name = "title")
private String title;
@Column(nullable = false, unique = false, name = "text")
private String text;
// Constructors, getters, setters
}
DbTestTopic.java :
Code:
@Entity
@Table(name = "test_topic")
@javax.persistence.TableGenerator(name="DbTestTopic_GEN",
table="id_sequence",
pkColumnName = "entity_name",
valueColumnName = "value",
pkColumnValue="DbTestTopic",
allocationSize=20)
public class DbTestTopic implements Serializable {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy = GenerationType.TABLE, generator="DbTestTopic_GEN")
private Integer id;
@Column(nullable = false, unique = true, name = "name")
private String name;
@Column(nullable = true, unique = false, name = "nb_messages")
private Integer nbMessages;
// Constructors, getters, setters
}
Thanks a lot for any help !!