public class A{
private A.id id;
private String bar;
public static class Id{
private String a;
private String b;
//重写eqauls和hashcode方法
//getter,setter
}
//getter,setter
}
映射文件:
<hibernate-mapping package="org.xx.yyy.zzzz">
<!--
Depends on Hibernate configuration with hibernate.hbm2ddl.auto=update.
-->
<class name="A" table="TA">
<composite-id name="id" class="XmlSchemaGrant$Id">
<key-property name="a" type="string">
<column name="a" />
</key-property>
<key-property name="b" type="string">
<column name="b" />
</key-property>
</composite-id>
<property name="bar" column="bar" type="text"
not-null="false" />
</class>
注意Java类中,Id类必须是静态类,否则会报No default constructor for entity的错误。
注意配置文件中,配置联合主键的class中间要用$符号。
关于静态内部类,其相当于写在Java文件中的普通类。可参考以下文字:
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3
https://forum.hibernate.org/viewtopic.php?f=1&t=973414&view=previous
写道
Check out this section of the Java language spec that explains the difference between static and non-static inner classes:
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3
A static inner class is conceptually no different than a regular general class declared in a .java file.
分享到:
相关推荐
hibernate的联合主键怎么设置、hibernate的联合主键怎么设置.doc
hibernate中用到联合主键的看看就会了很棒的资料
Hibernate联合主键,MyEclipse的例子
第一、将联合主键的字段单独放在一个类中,该类需要实现java.io.Serializable接口并重写equals和hascode,再将该类注解为@Embeddable,最后在主类中(该类不包含联合主键类中的字段)保存该联合主键类的一个引用,并...
关于Hibernate的各种主键生成策略与配置详解
NULL 博文链接:https://liuna718-163-com.iteye.com/blog/748089
hibernate复合主键设置,里面很全面的配置,可以拿到直接用
hibernate 无主键表映射资源说明: 1. 简单Demo 2. Demo对应的sql语句 3. 对应博客文档
主要介绍了java hibernate使用注解来定义联合主键的相关资料,需要的朋友可以参考下
复合主键映射 <br>通常将复合主键相关属性,单独抽取出来,建立一个独立的类 * 必须实现序列化接口 * 必须实现equals和hashcode方法 采用标签进行映射,其它属性采用正常映射
hibernate复合主键的实例,hibernate复合主键的实例。
hibernate一对一主键关联代码实现
本文是讲解的是hibernate3.2的主键生成方式,通过annotation来实现,详细的分析了主键在hibernate的生成以及在真实项目的运用。。。。
Myeclipse自动生成Hibernate配置文件及实体类映射ORM配置文件--hibernate方式
demo代码; 博客地址:http://blog.csdn.net/smilefyx/article/details/48951933
hibernate的主键生成策略介绍,详细介绍了有关hibernate的常用主键生成策略,希望对一些正在学习hibernate的同学有一定的帮助
NULL 博文链接:https://zhangzhi199129.iteye.com/blog/1663919
NULL 博文链接:https://paladin1988.iteye.com/blog/1639102
Hibernate配置文件Hibernate配置文件Hibernate配置文件