hibernate query VO

The requirement is very simple, that is, to associate two entities and query one more name. This is troublesome, use resultTransformer to do it. just need to write

	String hql = "select a.id as id, "
				+ "a.assetsNo as assetsNo,"
				+ "a.assetsSpecification as assetsSpecification,"
				+ "a.bxBeginTime as bxBeginTime,"
				+ "a.bxEndTime as bxEndTime,"
				+ "a.contractId as contractId,"
				+ "a.clientId as clientId,"
				+ "a.assetsType as assetsType,"
				+ "a.manufacturerCode as manufacturerCode,"
				+ "a.supplierCode as supplierCode,"
				+ "a.count as count,"
				+ "a.installationLocation as installationLocation, "
				+ "at.name as assetsTypeName from Assets a, AssetsType at where a.assetsType=at.id and a.clientId=:clientId and a.contractId=:contractId";
		
		return findPageByHql(page, hql, params, Assets.class);

 Note: as must be added, otherwise it will report an error Could not find setter for 0 on class com.kingen.bean.Assets

 

In order to associate a name, I need to write so many more lines, and stupidly list all the fields of this class and add as.

Hibernate is too inefficient to play like this! No wonder they are switching to Mybatis now.

 

I originally wanted to use addEntity of sql instead of hql, so I only need to select a.*, name, but name is transient and cannot set the value (addEntity only works on hibernate entities)

 

	private String assetsTypeName;

	// Constructors

	@Transient
	public String getAssetsTypeName() {
		return assetsTypeName;
	}

 

 

I'm really speechless, what did you do when you checked hibernate VO? ?

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326644930&siteId=291194637
vo