PostgreSQL データベースで休止状態を使用して 2 つの関連付けられたテーブルを作成する際に問題があります。インターネット サイトで提案されているほぼすべての Hibernate アプローチを試したにもかかわらず、同じエラーが発生するため、問題はデータベース (構成?) にあると考えがちです。PostgreSql データベースを使用する前に必要な構成はありますか? 表示されるエラーを他の方法で説明することはできません。
「関係部門が存在しません」
次のように、2 つのエンティティ Employee と Department を結合します。
@Entity
@Table(name="EMPLOYEE")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="employee_id")
private Long employeeId;
.
.
.
@ManyToOne
@JoinColumn(name="department_id")
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
private Department department;
と
@Entity
@Table(name="DEPARTMENT")
public class Department implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="DEPARTMENT_ID")
private Long departmentId;
.
.
.
@OneToMany(mappedBy="department")
public Set<Employee> getEmployees() {
return employees;
}
public void setEmployees(Set<Employee> employees) {
this.employees = employees;
}
private Set<Employee> employees;
次のように、メイン メソッドでいくつかのレコードを使用してテーブルを作成しようとしています。
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
Department department = new Department();
department.setDepartmentName("Sales");
session.persist(department);
Employee emp1 = new Employee("Nina", "Mayers", "111");
Employee emp2 = new Employee("Tony", "Almeida", "222");
emp1.setDepartment(department);
emp2.setDepartment(department);
session.persist(emp1);
session.persist(emp2);
session.getTransaction().commit();
session.close();
次の行にエラーが表示されます。session.persist(department);
テーブル/リレーションを認識できず、エラーが発生する理由を見つけるのを手伝ってくれるPostgreSqlデータベースの経験がある人はいますか?
「関係部署が存在しません」?
アップデート:
ログファイルを見ました。Eclipse からも通常のメッセージが表示された後、メッセージの最後の行は「ターゲット マシンがアクティブに拒否したため、接続できませんでした」です。問題はおそらく接続にあると推測します。接続を確立するために (pgAdmin で) 設定する必要があるプロパティはありますか? ラインを設定しました
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/testDB</property>
Eclipse の cfg.xml ファイル内。