实体
JAVA:
- import java.io.Serializable;
- import javax.persistence.Column;
- import javax.persistence.EmbeddedId;
- import javax.persistence.Entity;
- import javax.persistence.Table;
- @Table(name = "FOR_GD_CONFIG")
- @EmbeddedId
- private DbConfigPk allPk;
- // @AttributeOverrides( {
- // @AttributeOverride(name = "fid", column = @Column(name = "FLOWID",
- // nullable = false)),
- // @AttributeOverride(name = "m", column = @Column(name = "MARK", nullable =
- // false)) })
- public DbConfigPk getAllPk() {
- return this.allPk;
- }
- public void setAllPk(DbConfigPk allPk) {
- this.allPk = allPk;
- }
- @Column(name = "MARK_CN", nullable = true)
- private String mC;
- return this.mC;
- }
- this.mC = mC;
- }
- @Column(name = "COLUMN_NAME", nullable = false)
- private String cn;
- return this.cn;
- }
- this.cn = cn;
- }
- }
实体中的复合主键
JAVA:
- package com.rizon.lyj.gwgd.db;
- import java.io.Serializable;
- import javax.persistence.Column;
- import javax.persistence.Embeddable;
- /**
- * - 19. -
- *
- * 复合主键~good luck~
- *
- * @author <a href="http://www.LL19.com/">LL19.com</a>
- * @version 1.0
- */
- @Embeddable
- @Column(name = "FLOWID", nullable = false)
- private Long fid;
- return this.fid;
- }
- this.fid = fid;
- }
- @Column(name = "MARK", nullable = false)
- private String m;
- return this.m;
- }
- this.m = m;
- }
- }
BEAN
JAVA:
实体和BEAN的转换类
JAVA:
- public class DbTools {
- public static DbConfigEntity toDbConfigEntity(DbConfigBean bean) {
- if (bean == null) {
- return null;
- }
- DbConfigEntity entity = new DbConfigEntity();
- entity.setCn(bean.getCn());
- DbConfigPk dbConfigPk = new DbConfigPk();
- dbConfigPk.setFId(bean.getFId());
- dbConfigPk.setM(bean.getM());
- entity.setAllPk(dbConfigPk);
- entity.setMc(bean.getMc());
- return entity;
- }
- public static DbConfigBean toDbConfigBean(DbConfigEntity entity) {
- if (entity == null) {
- return null;
- }
- DbConfigBean bean = new DbConfigBean();
- bean.setCn(entity.getCn());
- bean.setFId(entity.getAllPk().getFId());
- bean.setM(entity.getAllPk().getM());
- bean.setMc(entity.getMc());
- return bean;
- }
- }
调用
JAVA:
SERVICE中
JAVA:
- public List< DbConfigBean > find0() {
- Criterion[] criterion = new Criterion[1];
- criterion[0] = Comparison.eq("allPk.fid", (long) 0);
- List< DbConfigEntity > entitys = this.gbConfigDao.find(criterion);
- List< DbConfigBean > beans = new ArrayList< DbConfigBean >(entitys.size());
- for (DbConfigEntity entity : entitys) {
- beans.add(DbTools.toDbConfigBean(entity));
- }
- return beans;
- }
- Criterion[] criterion = new Criterion[1];
- criterion[0] = Comparison.eq("allPk.m", Mark);
- OrderBy[] orders = new OrderBy[1];
- orders[0] = (OrderBy.asc("allPk.fid"));
- List< DbConfigEntity > entitys = this.gbConfigDao.find(orders, criterion);
- List< DbConfigBean > beans = new ArrayList< DbConfigBean >(entitys.size());
- for (DbConfigEntity entity : entitys) {
- beans.add(DbTools.toDbConfigBean(entity));
- }
- return beans;
- }