实体:product
@Entity
public class Product {
private String productNo;
private String name;
private String chandi;
private ProductType productType;
@Id
public String getProductNo() {
return productNo;
}
public void setProductNo(String productNo) {
this.productNo = productNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getChandi() {
return chandi;
}
public void setChandi(String chandi) {
this.chandi = chandi;
}
@ManyToOne(cascade ="CascadeType.All")
@JoinColumn(name="productType_id")
public ProductType getProductType() {
return productType;
}
public void setProductType(ProductType productType) {
this.productType = productType;
}
}
实体类ProductType
@Entity
public class ProductType {
private String typeNo;
private String Name;
private Set<Product> products;
@Id
public String getTypeNo() {
return typeNo;
}
public void setTypeNo(String typeNo) {
this.typeNo = typeNo;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
@OneToMany(mappedBy="productType")
public Set<Product> getProducts() {
return products;
}
public void setProducts(Set<Product> products) {
this.products = products;
}
}
如果关联查询:createQuery("select p.chandit.name from Product p left join p.productType t group by p.productType ")会返回object类型要想对实体处理可以采取如下措施:
1、增加一个类(字段名为查询的字段名,要生成对应的geter seter方法,并且一定要有构造函数,且构造函数的参数是查询的字段)
public class ProductAndType {
private String name;
private String chandi;
public Product(String name, String chandi) {
this.name = name;
this.chandi = chandi;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getChandi() {
return chandi;
}
public void setChandi(String chandi) {
this.chandi = chandi;
}
}
2、修改查询语句createQuery("select new 包名.ProductAndType( p.chandi t.name )from Product p left join p.productType t group by p.productType ")这样即可转为ProductAndType类型,可对其操作。
相关推荐
赠送jar包:hibernate-jpa-2.1-api-1.0.2.Final.jar; 赠送原API文档:hibernate-jpa-2.1-api-1.0.2.Final-javadoc.jar; 赠送源代码:hibernate-jpa-2.1-api-1.0.2.Final-sources.jar; 赠送Maven依赖信息文件:...
hibernate jpa开发需要的所有包 jpa-jar包 hibernate开发
开发hibernate jpa 依赖的所有jar,mysql 驱动jar包等。
该套是HibernateJPA的完整JAR包,只需导入全部jar包就可搭建Hibernate jpa对MySQL数据库的持久化操作
hibernate jpa 用到的所有jar
自定义的代码生成工具,可以根据数据库表来自动生成实体类,dao层,用于Hibernate和SpringDataJPA,支持lombok注解@Data和普通方式。单独使用需要jdbc连接包和Hibernate-jpa包。 使用方法 public static void main...
赠送jar包:hibernate-jpa-2.1-api-1.0.2.Final.jar; 赠送原API文档:hibernate-jpa-2.1-api-1.0.2.Final-javadoc.jar; 赠送源代码:hibernate-jpa-2.1-api-1.0.2.Final-sources.jar; 赠送Maven依赖信息文件:...
HibernateJPA+Struts2.0+MariaDB实现登录功能
包括TOPLink JPA,Hibernate JPA,Open Jpa,jpa批注
使用学生(student)、老师(teacher)、班级(class)反映出Hibernate annotation JPA 的一对多、多对多、多对一的关联。或许对您有用
修改jdbc.properties 运行起来后 ,输入地址 localhost:8080/ajie-wechat/saveUser.htm 数据库有数据表示成功
hibernate-jpa-2.0-api-1.0.1.Final-sources.jar hibernate jpa 源代码
JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询...
hibernate-jpa-2.1-api-1.0.0.final-sources.jar 源码 hibernate-jpa-2.1-api-1.0.0.final-sources.jar 源码
Spring hibernate jpa Project sample
主要介绍了idea hibernate jpa 生成实体类的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
hibernate-jpa.jar
JPA-Hibernate包, JPA-Hibernate包, JPA-Hibernate包, JPA-Hibernate包, JPA-Hibernate包, JPA-Hibernate包
5.Hibernate 05 Hibernate结合JPA1
JPA Hibernate 帮你详细解释jpa中注解的详细用法 帮你更好的去了解和运用