- 浏览: 75275 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
jnjeC:
SimpleMailMessage simpleMailM ...
MailSender和SimpleMailMessage的基本用法 -
duninet:
不用这么复杂,其实获取index变通一下即可:先调用getRo ...
easyui datagrid 动态删除行 -
du_bo:
请问楼主这个如何save()
hibernate 无主键操作——联合主键 -
jugg:
擦 证书不行
CAS软件的安装 -
zyj177484:
能请问下,我用lucene3.6 为何用不了QueryResu ...
Lucene学习入门3
今天给了两个表,但是没有主键,傻眼了,没有配到过没有主键的表(哦承认自己少见多怪了),上网查了一下要用联合主键,把一条数据看做一个主键,上网查了一下都说做好不要用联合主键,不用联合主键应该怎么做呢?思考中......
下来说说使用联合主键的方法吧。
用Myeclipse用具生成了四个类,分别是:TradeList.java,TradeListId.java,TradeInfo.java和TradeInfoId.java
具体的让我们来看一下:
package com.iplamp.enterprise.model; import javax.persistence.Column; import javax.persistence.Embeddable; /** * TradeListId entity. @author MyEclipse Persistence Tools */ @Embeddable public class TradeListId implements java.io.Serializable { // Fields private String tradeId; private String categoryId; private String tradeName; private String applier; private Integer EId; // Property accessors @Column(name = "trade_id", length = 20) public String getTradeId() { return this.tradeId; } public void setTradeId(String tradeId) { this.tradeId = tradeId; } @Column(name = "category_id", length = 20) public String getCategoryId() { return this.categoryId; } public void setCategoryId(String categoryId) { this.categoryId = categoryId; } @Column(name = "trade_name") public String getTradeName() { return this.tradeName; } public void setTradeName(String tradeName) { this.tradeName = tradeName; } @Column(name = "applier") public String getApplier() { return this.applier; } public void setApplier(String applier) { this.applier = applier; } @Column(name = "e_id", nullable = false) public Integer getEId() { return this.EId; } public void setEId(Integer EId) { this.EId = EId; } public boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof TradeListId)) return false; TradeListId castOther = (TradeListId) other; return ((this.getTradeId() == castOther.getTradeId()) || (this .getTradeId() != null && castOther.getTradeId() != null && this .getTradeId().equals(castOther.getTradeId()))) && ((this.getCategoryId() == castOther.getCategoryId()) || (this .getCategoryId() != null && castOther.getCategoryId() != null && this .getCategoryId().equals(castOther.getCategoryId()))) && ((this.getTradeName() == castOther.getTradeName()) || (this .getTradeName() != null && castOther.getTradeName() != null && this .getTradeName().equals(castOther.getTradeName()))) && ((this.getApplier() == castOther.getApplier()) || (this .getApplier() != null && castOther.getApplier() != null && this .getApplier().equals(castOther.getApplier()))) && ((this.getEId() == castOther.getEId()) || (this.getEId() != null && castOther.getEId() != null && this.getEId().equals( castOther.getEId()))); } public int hashCode() { int result = 17; result = 37 * result + (getTradeId() == null ? 0 : this.getTradeId().hashCode()); result = 37 * result + (getCategoryId() == null ? 0 : this.getCategoryId() .hashCode()); result = 37 * result + (getTradeName() == null ? 0 : this.getTradeName().hashCode()); result = 37 * result + (getApplier() == null ? 0 : this.getApplier().hashCode()); result = 37 * result + (getEId() == null ? 0 : this.getEId().hashCode()); return result; } } import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Table; /** * TradeList entity. @author MyEclipse Persistence Tools */ @Entity @Table(name = "ie_trade_list", catalog = "iplamp_enterprise") public class TradeList implements java.io.Serializable { public static String FIELD_EID = "id.EId" ; public static String FIELD_TRADEID = "id.tradeId" ; // Fields private TradeListId id; // Property accessors @EmbeddedId @AttributeOverrides({ @AttributeOverride(name = "tradeId", column = @Column(name = "trade_id", length = 20)), @AttributeOverride(name = "categoryId", column = @Column(name = "category_id", length = 20)), @AttributeOverride(name = "tradeName", column = @Column(name = "trade_name")), @AttributeOverride(name = "applier", column = @Column(name = "applier")), @AttributeOverride(name = "EId", column = @Column(name = "e_id", nullable = false)) }) public TradeListId getId() { return this.id; } public void setId(TradeListId id) { this.id = id; } } import javax.persistence.Column; import javax.persistence.Embeddable; /** * TradeInfoId entity. @author MyEclipse Persistence Tools */ @Embeddable public class TradeInfoId implements java.io.Serializable { // Fields private String regNo; private String catId; private String applyDate; private String applierCn; private String applierAddrCn; private String applierEn; private String applierAddrEn; private String tradeImgUrl; private String tradeImgThumbUrl; private String imgUrl; private String imgThumbUrl; private String serviceList; private String similarGroup; private String csggId; private String zcggId; private String csggDate; private String zcggDate; private String validYear; private String hqzdDate; private String gjczDate; private String priorityDate; private String agentName; private String specifiedColor; private String tradeType; private String isShare; private String remark; private String tradeflow; // Constructors // Property accessors @Column(name = "regNo", length = 20) public String getRegNo() { return this.regNo; } public void setRegNo(String regNo) { this.regNo = regNo; } @Column(name = "catId", length = 20) public String getCatId() { return this.catId; } public void setCatId(String catId) { this.catId = catId; } @Column(name = "applyDate", length = 20) public String getApplyDate() { return this.applyDate; } public void setApplyDate(String applyDate) { this.applyDate = applyDate; } @Column(name = "applierCN") public String getApplierCn() { return this.applierCn; } public void setApplierCn(String applierCn) { this.applierCn = applierCn; } @Column(name = "applierAddrCN") public String getApplierAddrCn() { return this.applierAddrCn; } public void setApplierAddrCn(String applierAddrCn) { this.applierAddrCn = applierAddrCn; } @Column(name = "applierEN") public String getApplierEn() { return this.applierEn; } public void setApplierEn(String applierEn) { this.applierEn = applierEn; } @Column(name = "applierAddrEN") public String getApplierAddrEn() { return this.applierAddrEn; } public void setApplierAddrEn(String applierAddrEn) { this.applierAddrEn = applierAddrEn; } @Column(name = "tradeImgUrl") public String getTradeImgUrl() { return this.tradeImgUrl; } public void setTradeImgUrl(String tradeImgUrl) { this.tradeImgUrl = tradeImgUrl; } @Column(name = "tradeImgThumbUrl") public String getTradeImgThumbUrl() { return this.tradeImgThumbUrl; } public void setTradeImgThumbUrl(String tradeImgThumbUrl) { this.tradeImgThumbUrl = tradeImgThumbUrl; } @Column(name = "imgUrl") public String getImgUrl() { return this.imgUrl; } public void setImgUrl(String imgUrl) { this.imgUrl = imgUrl; } @Column(name = "imgThumbUrl") public String getImgThumbUrl() { return this.imgThumbUrl; } public void setImgThumbUrl(String imgThumbUrl) { this.imgThumbUrl = imgThumbUrl; } @Column(name = "serviceList") public String getServiceList() { return this.serviceList; } public void setServiceList(String serviceList) { this.serviceList = serviceList; } @Column(name = "similarGroup") public String getSimilarGroup() { return this.similarGroup; } public void setSimilarGroup(String similarGroup) { this.similarGroup = similarGroup; } @Column(name = "csggId") public String getCsggId() { return this.csggId; } public void setCsggId(String csggId) { this.csggId = csggId; } @Column(name = "zcggId") public String getZcggId() { return this.zcggId; } public void setZcggId(String zcggId) { this.zcggId = zcggId; } @Column(name = "csggDate") public String getCsggDate() { return this.csggDate; } public void setCsggDate(String csggDate) { this.csggDate = csggDate; } @Column(name = "zcggDate") public String getZcggDate() { return this.zcggDate; } public void setZcggDate(String zcggDate) { this.zcggDate = zcggDate; } @Column(name = "validYear") public String getValidYear() { return this.validYear; } public void setValidYear(String validYear) { this.validYear = validYear; } @Column(name = "hqzdDate") public String getHqzdDate() { return this.hqzdDate; } public void setHqzdDate(String hqzdDate) { this.hqzdDate = hqzdDate; } @Column(name = "gjczDate") public String getGjczDate() { return this.gjczDate; } public void setGjczDate(String gjczDate) { this.gjczDate = gjczDate; } @Column(name = "priorityDate") public String getPriorityDate() { return this.priorityDate; } public void setPriorityDate(String priorityDate) { this.priorityDate = priorityDate; } @Column(name = "agentName") public String getAgentName() { return this.agentName; } public void setAgentName(String agentName) { this.agentName = agentName; } @Column(name = "specifiedColor") public String getSpecifiedColor() { return this.specifiedColor; } public void setSpecifiedColor(String specifiedColor) { this.specifiedColor = specifiedColor; } @Column(name = "tradeType") public String getTradeType() { return this.tradeType; } public void setTradeType(String tradeType) { this.tradeType = tradeType; } @Column(name = "isShare") public String getIsShare() { return this.isShare; } public void setIsShare(String isShare) { this.isShare = isShare; } @Column(name = "remark") public String getRemark() { return this.remark; } public void setRemark(String remark) { this.remark = remark; } @Column(name = "tradeflow") public String getTradeflow() { return this.tradeflow; } public void setTradeflow(String tradeflow) { this.tradeflow = tradeflow; } public boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof TradeInfoId)) return false; TradeInfoId castOther = (TradeInfoId) other; return ((this.getRegNo() == castOther.getRegNo()) || (this.getRegNo() != null && castOther.getRegNo() != null && this.getRegNo().equals( castOther.getRegNo()))) && ((this.getCatId() == castOther.getCatId()) || (this .getCatId() != null && castOther.getCatId() != null && this .getCatId().equals(castOther.getCatId()))) && ((this.getApplyDate() == castOther.getApplyDate()) || (this .getApplyDate() != null && castOther.getApplyDate() != null && this .getApplyDate().equals(castOther.getApplyDate()))) && ((this.getApplierCn() == castOther.getApplierCn()) || (this .getApplierCn() != null && castOther.getApplierCn() != null && this .getApplierCn().equals(castOther.getApplierCn()))) && ((this.getApplierAddrCn() == castOther.getApplierAddrCn()) || (this .getApplierAddrCn() != null && castOther.getApplierAddrCn() != null && this .getApplierAddrCn() .equals(castOther.getApplierAddrCn()))) && ((this.getApplierEn() == castOther.getApplierEn()) || (this .getApplierEn() != null && castOther.getApplierEn() != null && this .getApplierEn().equals(castOther.getApplierEn()))) && ((this.getApplierAddrEn() == castOther.getApplierAddrEn()) || (this .getApplierAddrEn() != null && castOther.getApplierAddrEn() != null && this .getApplierAddrEn() .equals(castOther.getApplierAddrEn()))) && ((this.getTradeImgUrl() == castOther.getTradeImgUrl()) || (this .getTradeImgUrl() != null && castOther.getTradeImgUrl() != null && this .getTradeImgUrl().equals(castOther.getTradeImgUrl()))) && ((this.getTradeImgThumbUrl() == castOther .getTradeImgThumbUrl()) || (this.getTradeImgThumbUrl() != null && castOther.getTradeImgThumbUrl() != null && this .getTradeImgThumbUrl().equals( castOther.getTradeImgThumbUrl()))) && ((this.getImgUrl() == castOther.getImgUrl()) || (this .getImgUrl() != null && castOther.getImgUrl() != null && this .getImgUrl().equals(castOther.getImgUrl()))) && ((this.getImgThumbUrl() == castOther.getImgThumbUrl()) || (this .getImgThumbUrl() != null && castOther.getImgThumbUrl() != null && this .getImgThumbUrl().equals(castOther.getImgThumbUrl()))) && ((this.getServiceList() == castOther.getServiceList()) || (this .getServiceList() != null && castOther.getServiceList() != null && this .getServiceList().equals(castOther.getServiceList()))) && ((this.getSimilarGroup() == castOther.getSimilarGroup()) || (this .getSimilarGroup() != null && castOther.getSimilarGroup() != null && this .getSimilarGroup().equals(castOther.getSimilarGroup()))) && ((this.getCsggId() == castOther.getCsggId()) || (this .getCsggId() != null && castOther.getCsggId() != null && this .getCsggId().equals(castOther.getCsggId()))) && ((this.getZcggId() == castOther.getZcggId()) || (this .getZcggId() != null && castOther.getZcggId() != null && this .getZcggId().equals(castOther.getZcggId()))) && ((this.getCsggDate() == castOther.getCsggDate()) || (this .getCsggDate() != null && castOther.getCsggDate() != null && this .getCsggDate().equals(castOther.getCsggDate()))) && ((this.getZcggDate() == castOther.getZcggDate()) || (this .getZcggDate() != null && castOther.getZcggDate() != null && this .getZcggDate().equals(castOther.getZcggDate()))) && ((this.getValidYear() == castOther.getValidYear()) || (this .getValidYear() != null && castOther.getValidYear() != null && this .getValidYear().equals(castOther.getValidYear()))) && ((this.getHqzdDate() == castOther.getHqzdDate()) || (this .getHqzdDate() != null && castOther.getHqzdDate() != null && this .getHqzdDate().equals(castOther.getHqzdDate()))) && ((this.getGjczDate() == castOther.getGjczDate()) || (this .getGjczDate() != null && castOther.getGjczDate() != null && this .getGjczDate().equals(castOther.getGjczDate()))) && ((this.getPriorityDate() == castOther.getPriorityDate()) || (this .getPriorityDate() != null && castOther.getPriorityDate() != null && this .getPriorityDate().equals(castOther.getPriorityDate()))) && ((this.getAgentName() == castOther.getAgentName()) || (this .getAgentName() != null && castOther.getAgentName() != null && this .getAgentName().equals(castOther.getAgentName()))) && ((this.getSpecifiedColor() == castOther.getSpecifiedColor()) || (this .getSpecifiedColor() != null && castOther.getSpecifiedColor() != null && this .getSpecifiedColor().equals( castOther.getSpecifiedColor()))) && ((this.getTradeType() == castOther.getTradeType()) || (this .getTradeType() != null && castOther.getTradeType() != null && this .getTradeType().equals(castOther.getTradeType()))) && ((this.getIsShare() == castOther.getIsShare()) || (this .getIsShare() != null && castOther.getIsShare() != null && this .getIsShare().equals(castOther.getIsShare()))) && ((this.getRemark() == castOther.getRemark()) || (this .getRemark() != null && castOther.getRemark() != null && this .getRemark().equals(castOther.getRemark()))) && ((this.getTradeflow() == castOther.getTradeflow()) || (this .getTradeflow() != null && castOther.getTradeflow() != null && this .getTradeflow().equals(castOther.getTradeflow()))); } public int hashCode() { int result = 17; result = 37 * result + (getRegNo() == null ? 0 : this.getRegNo().hashCode()); result = 37 * result + (getCatId() == null ? 0 : this.getCatId().hashCode()); result = 37 * result + (getApplyDate() == null ? 0 : this.getApplyDate().hashCode()); result = 37 * result + (getApplierCn() == null ? 0 : this.getApplierCn().hashCode()); result = 37 * result + (getApplierAddrCn() == null ? 0 : this.getApplierAddrCn() .hashCode()); result = 37 * result + (getApplierEn() == null ? 0 : this.getApplierEn().hashCode()); result = 37 * result + (getApplierAddrEn() == null ? 0 : this.getApplierAddrEn() .hashCode()); result = 37 * result + (getTradeImgUrl() == null ? 0 : this.getTradeImgUrl() .hashCode()); result = 37 * result + (getTradeImgThumbUrl() == null ? 0 : this .getTradeImgThumbUrl().hashCode()); result = 37 * result + (getImgUrl() == null ? 0 : this.getImgUrl().hashCode()); result = 37 * result + (getImgThumbUrl() == null ? 0 : this.getImgThumbUrl() .hashCode()); result = 37 * result + (getServiceList() == null ? 0 : this.getServiceList() .hashCode()); result = 37 * result + (getSimilarGroup() == null ? 0 : this.getSimilarGroup() .hashCode()); result = 37 * result + (getCsggId() == null ? 0 : this.getCsggId().hashCode()); result = 37 * result + (getZcggId() == null ? 0 : this.getZcggId().hashCode()); result = 37 * result + (getCsggDate() == null ? 0 : this.getCsggDate().hashCode()); result = 37 * result + (getZcggDate() == null ? 0 : this.getZcggDate().hashCode()); result = 37 * result + (getValidYear() == null ? 0 : this.getValidYear().hashCode()); result = 37 * result + (getHqzdDate() == null ? 0 : this.getHqzdDate().hashCode()); result = 37 * result + (getGjczDate() == null ? 0 : this.getGjczDate().hashCode()); result = 37 * result + (getPriorityDate() == null ? 0 : this.getPriorityDate() .hashCode()); result = 37 * result + (getAgentName() == null ? 0 : this.getAgentName().hashCode()); result = 37 * result + (getSpecifiedColor() == null ? 0 : this.getSpecifiedColor() .hashCode()); result = 37 * result + (getTradeType() == null ? 0 : this.getTradeType().hashCode()); result = 37 * result + (getIsShare() == null ? 0 : this.getIsShare().hashCode()); result = 37 * result + (getRemark() == null ? 0 : this.getRemark().hashCode()); result = 37 * result + (getTradeflow() == null ? 0 : this.getTradeflow().hashCode()); return result; } } import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Table; /** * TradeInfo entity. @author MyEclipse Persistence Tools */ @Entity @Table(name = "ie_trade_info", catalog = "iplamp_enterprise") public class TradeInfo implements java.io.Serializable { public static String FIELD_REGNO = "id.regNo"; // Fields private TradeInfoId id; // Constructors /** * default constructor */ public TradeInfo() { } /** * full constructor */ public TradeInfo(TradeInfoId id) { this.id = id; } // Property accessors @EmbeddedId @AttributeOverrides({ @AttributeOverride(name = "regNo", column = @Column(name = "regNo", length = 20)), @AttributeOverride(name = "catId", column = @Column(name = "catId", length = 20)), @AttributeOverride(name = "applyDate", column = @Column(name = "applyDate", length = 20)), @AttributeOverride(name = "applierCn", column = @Column(name = "applierCN")), @AttributeOverride(name = "applierAddrCn", column = @Column(name = "applierAddrCN")), @AttributeOverride(name = "applierEn", column = @Column(name = "applierEN")), @AttributeOverride(name = "applierAddrEn", column = @Column(name = "applierAddrEN")), @AttributeOverride(name = "tradeImgUrl", column = @Column(name = "tradeImgUrl")), @AttributeOverride(name = "tradeImgThumbUrl", column = @Column(name = "tradeImgThumbUrl")), @AttributeOverride(name = "imgUrl", column = @Column(name = "imgUrl")), @AttributeOverride(name = "imgThumbUrl", column = @Column(name = "imgThumbUrl")), @AttributeOverride(name = "serviceList", column = @Column(name = "serviceList")), @AttributeOverride(name = "similarGroup", column = @Column(name = "similarGroup")), @AttributeOverride(name = "csggId", column = @Column(name = "csggId")), @AttributeOverride(name = "zcggId", column = @Column(name = "zcggId")), @AttributeOverride(name = "csggDate", column = @Column(name = "csggDate")), @AttributeOverride(name = "zcggDate", column = @Column(name = "zcggDate")), @AttributeOverride(name = "validYear", column = @Column(name = "validYear")), @AttributeOverride(name = "hqzdDate", column = @Column(name = "hqzdDate")), @AttributeOverride(name = "gjczDate", column = @Column(name = "gjczDate")), @AttributeOverride(name = "priorityDate", column = @Column(name = "priorityDate")), @AttributeOverride(name = "agentName", column = @Column(name = "agentName")), @AttributeOverride(name = "specifiedColor", column = @Column(name = "specifiedColor")), @AttributeOverride(name = "tradeType", column = @Column(name = "tradeType")), @AttributeOverride(name = "isShare", column = @Column(name = "isShare")), @AttributeOverride(name = "remark", column = @Column(name = "remark")), @AttributeOverride(name = "tradeflow", column = @Column(name = "tradeflow")) }) public TradeInfoId getId() { return this.id; } public void setId(TradeInfoId id) { this.id = id; } }
上面四个类是工具自动生成的。
下面做一个用根据e_id查询,带分页,按trade_id排序
/** * 获取所有的对象 * @return */ public List<TradeList> getAll() { return this.tradeListDao.loadAll(); } public List<TradeList> getTradeList(PageBean pageBean, Integer eId) { HibernateSearchCondition hsc = new HibernateSearchCondition(); hsc.addCriterion(Restrictions.eq(TradeList.FIELD_EID, eId)); // 按tradeId排序 hsc.addDESC(TradeList.FIELD_TRADEID); //降序 return getTradeListByPage(pageBean, hsc); }
上面这个查询条件就相当于
Criteria c = this.getSession().createCriteria(TradeList.class) .add(Restrictions.eq(TradeList.FIELD_EID, eId)) .addOrder(Order.desc(TradeList.FIELD_TRADEID));
条件就通过id.XXX(字段)来描述就可以了,其他的与有主键的相同
但是使用联合主键注意点 操作的时候自己注意点
建议:如非必要,不要使用联合主键,表中没有主键,但是在实体类中可以给某个字段建立主键关联,就像表中有主键一样就行了,但是必须保证作为主键的那个字段没有重复的值。
对视图的映射一般都没有主键,如果使用工具自动映射的话就会出现联合主键的,所以在映射的实体类中,我们可以把某个不能没有重复的值的字段当做主键来映射
相关推荐
【标题】与【描述】提及的是“Hibernate面试题专栏”,主要涵盖了全面的Hibernate面试题、笔试题以及相关问题,这表明我们将要讨论的是Java领域中著名的对象关系映射框架——Hibernate的相关知识。Hibernate是一个...
11. 联合主键与复合主键 对于多字段主键,可以使用`@IdClass`或`@EmbeddedId`注解进行配置。 12. 异步操作与批量处理 使用Hibernate的批处理更新或删除,可以显著提高性能。还可以结合JTA进行分布式事务管理。 ...
最后,书中可能还会讨论一些高级主题,如Hibernate的联合映射(Association Mapping)、继承映射(Inheritance Mapping)、复合主键(Composite Key)以及自定义类型(Custom Types)。这些特性允许开发者构建更复杂...
3. **对象关系映射**:深入讲解Hibernate的核心——对象关系映射(ORM),包括实体类的设计、属性注解、主键生成策略、关联映射(一对一、一对多、多对一、多对多)等,使开发者理解如何将Java对象与数据库表进行...
11. **联合实体映射**:讲解如何处理复杂的数据结构,如联合主键和复合实体。 12. **多态性与继承**:介绍如何在Hibernate中处理类继承关系,以及多态查询的实现。 13. **JPA集成**:如果指南也涵盖了JPA(Java ...
- 联合主键:多个字段共同组成主键。 - 继承映射:支持单表继承、多表继承等多种模式。 - 支持关联映射:一对一、一对多、多对一、多对多等各种关联关系。 - 支持延迟加载:只在真正需要时才加载关联对象,提高性能...
9. **查询语言HQL和Criteria API**:Hibernate提供了自己的SQL方言——HQL(Hibernate Query Language)和Criteria API,用于更面向对象的数据库查询。 10. **事务管理**:Hibernate支持编程式和声明式的事务管理,...
5. **Hibernate映射关系-多对多**:专门针对多对多关系,讲解如何配置中间表和联合主键,以实现两个实体间的复杂关联。 6. **Java反射机制**:虽然不是Hibernate的核心,但反射在ORM框架中扮演重要角色,用于动态...
《Hibernate 3.1.2Chinese》是针对Java开发者的一款持久化框架——Hibernate的中文教程。Hibernate是一个强大的ORM(对象关系映射)框架,它允许开发者用面向对象的方式来操作数据库,极大地简化了Java应用程序对...
《Hibernate——Java持久层框架深度解析》 Hibernate,作为Java领域中最流行的持久层框架之一,为开发者提供了便捷的对象关系映射(ORM)解决方案,极大地简化了数据库操作。本教程将从基础出发,全面深入地探讨...
3. **中间表配置**:虽然大多数情况下Hibernate会自动创建中间表,但你也可以通过`@JoinTable`注解自定义中间表的细节,如表名、联合主键等。例如: ```java @ManyToMany @JoinTable(name = "student_course", ...
组件映射允许将Java对象的字段或属性映射到数据库中的复合类型或联合主键。文档讲解了依赖对象、动态组件以及组件作为Map的索引或联合标识符的映射方法,提高了代码的可读性和维护性。 ### 继承映射 继承映射策略...
Hibernate提供了一种面向对象的查询语言——HQL,类似于SQL,但以对象和类为中心。此外,还可以使用Criteria API进行动态查询。 7. ** Criteria API** Criteria API提供了一种类型安全的查询方式,允许在运行时...
Hibernate 提供了自己的查询语言——HQL(Hibernate Query Language),它是面向对象的,语法类似SQL。此外,还可以使用 Criteria 查询、Query API 或者最新的JPQL(Java Persistence Query Language)。 7. **...
《Java JPA与Hibernate实战教程——模块二》 在Java开发领域,JPA(Java Persistence API)和Hibernate作为主流的ORM(对象关系映射)框架,对于数据持久化有着至关重要的作用。本教程的第二模块深入探讨了这两个...
《Java持久化API(JPA)2.0详解——基于javax.persistence-2.0.0.jar包》 Java持久化API(Java Persistence API,简称JPA)是Java平台上的一个标准,用于管理关系数据库中的数据。它为Java应用程序提供了一种对象/...
SQL不仅可以直接用于数据库查询,还可以通过编程语言(如Java、Python、C#等)中的数据库API或ORM框架(如JDBC、Hibernate、Django ORM)进行调用,实现数据的动态检索和更新。 #### 查询——SELECT语句的使用 ...
在设计一对一关系时,我们还应关注其在数据库映射中的实现,如使用外键约束或联合主键。在Java持久化API(JPA)或Hibernate等ORM框架中,可以配置实体之间的关系来实现一对一映射。 总结来说,Java中的对象一对一...
《Spring3.x企业应用开发实战》是在《精通Spring2.x——企业应用开发详解》的基础上,经过历时一年的重大调整改版而成的,本书延续了上一版本追求深度,注重原理,不停留在技术表面的写作风格,力求使读者在熟练...