私は休止状態のエラーがあります:
15:32:48,554 DEBUG SQL:111-apurement.user(groupe_id、username、password、email)の値(?、?、?、?)に
挿入15:32:48,664警告JDBCExceptionReporter:100-SQLエラー:1452、SQLState :23000
15:32:48,664エラーJDBCExceptionReporter:101-
子行を追加または更新できません:外部キー制約が失敗します(apurement
。user
、
CONSTRAINTgroupe_id
FOREIGN KEY(groupe_id
)REFERENCESgroupe
(groupe_id
)
ON DELETE NO ACTION ON UPDATE NO ACTION)
コードは、セッション管理用のLogic.javaです。
package com.beans;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.*;
public class Logic {
protected Configuration cfg;
protected SessionFactory sfg;
protected Session s;
protected Transaction tx;
public Logic() {
this.init();
}
public void init() {
this.setCfg(new Configuration().configure());
this.setSfg(this.getCfg().buildSessionFactory());
this.setS(this.getSfg().openSession());
this.setTx(this.getS().beginTransaction());
}
public Configuration getCfg() {
return cfg;
}
public void setCfg(Configuration cfg) {
this.cfg = cfg;
}
public SessionFactory getSfg() {
return sfg;
}
public void setSfg(SessionFactory sfg) {
this.sfg = sfg;
}
public Session getS() {
return s;
}
public void setS(Session s) {
this.s = s;
}
public Transaction getTx() {
return tx;
}
public void setTx(Transaction tx) {
this.tx = tx;
}
}
Userクラス:
package com.beans;
// Generated 3 janv. 2013 12:07:19 by Hibernate Tools 3.4.0.CR1
/**
* User generated by hbm2java
*/
public class User implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Integer userId;
private Groupe groupe;
private String username;
private String password;
private String email;
public User() {
}
public User(Groupe groupe, String username, String password, String email) {
this.groupe = groupe;
this.username = username;
this.password = password;
this.email = email;
}
public Integer getUserId() {
return this.userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Groupe getGroupe() {
return this.groupe;
}
public void setGroupe(Groupe groupe) {
this.groupe = groupe;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
}
user.hbm:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 3 janv. 2013 12:07:19 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="User" table="user" catalog="apurement">
<id name="userId" type="java.lang.Integer">
<column name="user_id" />
<generator class="identity" />
</id>
<many-to-one name="groupe" class="com.beans.Groupe" fetch="select">
<column name="groupe_id" not-null="true" />
</many-to-one>
<property name="username" type="string">
<column name="username" length="45" not-null="true" />
</property>
<property name="password" type="string">
<column name="password" length="45" not-null="true" />
</property>
<property name="email" type="string">
<column name="email" length="45" not-null="true" />
</property>
</class>
</hibernate-mapping>
groupe.java:
package com.beans;
// default package
// Generated 3 janv. 2013 12:07:19 by Hibernate Tools 3.4.0.CR1
import java.util.HashSet;
import java.util.Set;
/**
* Groupe generated by hbm2java
*/
public class Groupe implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Integer groupeId;
private String groupeName;
private String groupeRole;
private Set users = new HashSet(0);
public Groupe() {
}
public Groupe(String groupeName, String groupeRole) {
this.groupeName = groupeName;
this.groupeRole = groupeRole;
}
public Groupe(String groupeName, String groupeRole, Set users) {
this.groupeName = groupeName;
this.groupeRole = groupeRole;
this.users = users;
}
public Integer getGroupeId() {
return this.groupeId;
}
public void setGroupeId(Integer groupeId) {
this.groupeId = groupeId;
}
public String getGroupeName() {
return this.groupeName;
}
public void setGroupeName(String groupeName) {
this.groupeName = groupeName;
}
public String getGroupeRole() {
return this.groupeRole;
}
public void setGroupeRole(String groupeRole) {
this.groupeRole = groupeRole;
}
public Set getUsers() {
return this.users;
}
public void setUsers(Set users) {
this.users = users;
}
}
Groupe.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 3 janv. 2013 12:07:19 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="Groupe" table="groupe" catalog="apurement">
<id name="groupeId" type="java.lang.Integer">
<column name="groupe_id" />
<generator class="identity" />
</id>
<property name="groupeName" type="string">
<column name="groupe_name" length="100" not-null="true" />
</property>
<property name="groupeRole" type="string">
<column name="groupe_role" length="45" not-null="true" />
</property>
<set name="users" table="user" inverse="true" lazy="true" fetch="select">
<key>
<column name="groupe_id" not-null="true" />
</key>
<one-to-many class="com.beans.User" />
</set>
</class>
</hibernate-mapping>
hibernate.cfg:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate- configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="sf">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/apurement</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping class="com.beans.User" resource="com/beans/User.hbm.xml"/>
<mapping class="com.beans.Groupe" resource="com/beans/Groupe.hbm.xml"/>
</session-factory>
</hibernate-configuration>
何が起こっているのかわかりません。