一部のテーブルからエンティティの値をロードするための補助スタンドアロンアプリケーションがありますが、Hibernateがキー値を指定せずにレコードを作成しようとしているため(として指定されている場合でも@GeneratedValue(strategy=GenerationType.AUTO)
)、ドロップしています。
Beanは次のとおりです。
@Entity
public class Location implements Serializable {
private static final long serialVersionUID = 1L;
// startRegion attributes
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id = 0;
@ManyToOne(fetch = FetchType.LAZY)
private Location parent = null;
@Column(nullable=false)
private boolean active = false;
@OneToMany(mappedBy="parent", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
private Set<Location> divisions = null;
@OneToMany(mappedBy="location", fetch=FetchType.EAGER, cascade=CascadeType.ALL)
@MapKey(name="localeId")
private Map<String, Location_i18n> descriptions = new HashMap<String, Location_i18n>();
@Column(nullable=true, length=150)
private String path = null;
@Column(nullable=true, length=20)
private String prismaCode = null;
@Column(nullable=true, length=5)
private String shortCode = null;
}
Hibernateログに表示されるSQLにid
フィールドがありません:
insert into Location (active, parent_id, path, prismaCode, shortCode) values (?, ?, ?, ?, ?)
これは明らかに制約違反の例外を引き起こします。
からの関連プロパティpersistence.xml
:
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
欲求不満を増すために、前のプロセスでやや似たプロセスを実行しましたが、問題の原因となっている違いを見つけることができません。
私はMSSQL2008Expressに対してHibernate3.6.10と4.1.8の両方を試しました。
何か案は?少し早いですがお礼を。