如何编写查询以在hibernate条件中显示列表
Employee.java如何编写查询以在hibernate条件中显示列表,hibernate,spring-mvc,hibernate-criteria,map-projections,Hibernate,Spring Mvc,Hibernate Criteria,Map Projections,Employee.java @Table(name="EMPLOYEE") public class Employee { @Id @Column(name = "wid") @GeneratedValue(strategy= GenerationType.AUTO) private Integer wid; @Column(name = "wname") private String wname; @ManyToOne(optional = false) @JoinColumn(name
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
BloodGroup.java
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
@实体
@表(name=“BLOODGROUP”)
公共阶级血族{
@身份证
@列(name=“bid”)
@GeneratedValue(策略=GenerationType.AUTO)
私人整数投标;
@尺寸(最小值=1,最大值=30)
@列(name=“blood\u name”)
私密的血脉名称;
@OneToMany(mappedBy=“bloodgroup”,fetch=FetchType.LAZY,
targetEntity=Employee.class,cascade=CascadeType.PERSIST)
私人名单环境管理计划;
.....
//接球手和接球手
}
Section.java
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
@实体
@表(name=“SECTION”)
公共课组{
@身份证
@列(name=“sid”)
@GeneratedValue(策略=GenerationType.AUTO)
私有整数sid;
@列(name=“sname”)
@尺寸(最小值=2,最大值=30)
私有字符串sname;
@OneToMany(mappedBy=“section”,fetch=FetchType.LAZY,
targetEntity=Employee.class,cascade=CascadeType.PERSIST)
私人名单环境管理计划;
.....
//接球手和接球手
}
AbstractDao.java
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
公共抽象类AbstractDao{
私有最终类persistentClass;
@抑制警告(“未选中”)
公开摘要(){
this.persistentClass=(类)((ParameteredType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@自动连线
私人会话工厂会话工厂;
受保护会话getSession(){
返回sessionFactory.getCurrentSession();
}
@抑制警告(“未选中”)
公共T getByKey(主键){
return(T)getSession().get(persistentClass,key);
}
公共实体(T实体){
getSession().persist(实体);
}
公共无效更新(T实体){
getSession().update(实体);
}
公共作废删除(T实体){
getSession().delete(实体);
}
受保护的条件createEntityCriteria(){
返回getSession().createCriteria(persistentClass);
}
}
BloodGroupDaoImpl.java
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
@Repository(“bloodDao”)
公共类BloodDaoImpl扩展了AbstractDao
刀{
静态最终记录器Logger=LoggerFactory.getLogger(UserDaoImpl.class);
公共无效保存(血型血型血型){
持久性(血型);
}
@抑制警告(“未选中”)
公共列表listBloodGroup(){
标准=createEntityCriteria();
返回(列表)条件。列表();
}
}
SectionDaoImpl.java
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
@Repository(“sectionDao”)
公共类SectionDaoImpl扩展了AbstractDaoimplements
节道{
@凌驾
公共作废保存(第节){
(第二节);
}
@凌驾
公共列表所有部分(){
标准=createEntityCriteria();
返回(列表)条件。列表();
}
}
EmployeesDaoImpl.java
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
@Repository(“employeeDao”)
公共类EmployeeDaoImpl扩展了AbstractDao
实施雇员条例{
@凌驾
公共作废保存(员工){
(雇员);
}
@凌驾
公开名单所有员工(){
标准=createEntityCriteria();
返回(列表)条件。列表();
/*这显示了员工列表
带有外键的表。**我想显示带有对应项的员工列表
**BloobGroup**和**节**的值*/
}
}
BloodGroupServiceImpl.java
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
@Service(“bloodGroupService”)
@交易的
公共类bloodGroupServiceImpl实现了bloodGroupService{
@自动连线
私家血刀;
@凌驾
公共无效保存血型组(血型组血型组){
拯救(血族);
}
公共列表allBloodGroup(){
返回dao.listBloodGroup();
}
SectionServiceImpl.java
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
@Service(“sectionService”)
@交易的
公共类sectionServiceImpl实现sectionService{
@自动连线
私家道道;
@凌驾
公共作废保存(第节){
保存(节);
}
@凌驾
公共列表所有部分(){
返回dao.allSection();
}
EmployeeServiceImpl.java
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
@Service(“员工服务”)
@交易的
公共类employeeServiceImpl实现employeeService{
@自动连线
私人雇员道道;
@自动连线
私人血刀血刀;
@自动连线
私人部门部门部门部门部门部门部门部门部门部门部门部门部门部门部门部门部门部门部门部门;
@凌驾
公开名单所有员工(){
return dao.allEmployee();
}
@凌驾
公共作废保存(员工、内部血液组、内部部分){
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(员工);
}
}
AppController.java
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name = "wid")
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer wid;
@Column(name = "wname")
private String wname;
@ManyToOne(optional = false)
@JoinColumn(name = "bidd")
private BloodGroup bloodgroup;
@ManyToOne(optional = false)
@JoinColumn(name = "sidd")
private Section section;
.....
//Getters And Setters
}
@Entity
@Table(name="BLOODGROUP")
public class BloodGroup {
@Id
@Column(name = "bid")
@GeneratedValue (strategy= GenerationType.AUTO)
private Integer bid;
@Size(min=1,max = 30)
@Column(name = "blood_name")
private String blood_name;
@OneToMany(mappedBy = "bloodgroup",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
@Entity
@Table(name = "SECTION")
public class Section {
@Id
@Column(name = "sid")
@GeneratedValue (strategy = GenerationType.AUTO)
private Integer sid;
@Column(name = "sname")
@Size(min = 2 , max = 30)
private String sname;
@OneToMany(mappedBy = "section",fetch=FetchType.LAZY,
targetEntity=Employee.class, cascade=CascadeType.PERSIST)
private List<Employee> emp;
.....
//Getters And Setters
}
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
@SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType)
this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
@Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void update(T entity) {
getSession().update(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
@Repository("bloodDao")
public class BloodDaoImpl extends AbstractDao<Integer, BloodGroup>
implements BloodDao {
static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);
public void save(BloodGroup bloodgroup) {
persist(bloodgroup);
}
@SuppressWarnings("unchecked")
public List<BloodGroup> listBloodGroup() {
Criteria criteria = createEntityCriteria();
return (List<BloodGroup>) criteria.list();
}
}
@Repository("sectionDao")
public class SectionDaoImpl extends AbstractDao<Integer,Section>implements
SectionDao{
@Override
public void save(Section section) {
persist(section);
}
@Override
public List<Section> allSection() {
Criteria criteria = createEntityCriteria();
return (List<Section>) criteria.list();
}
}
@Repository("employeeDao")
public class EmployeeDaoImpl extends AbstractDao<Integer,Employee>
implements EmployeeDao{
@Override
public void save(Employee employee) {
persist(employee);
}
@Override
public List<Employee> allEmployee() {
Criteria criteria = createEntityCriteria();
return (List<Employee>) criteria.list();
/*This shows list of employee
table with foreign key. **I want to show list of employee with correspondent
value of **BloobGroup** and **Section**.*/
}
}
@Service("bloodGroupService")
@Transactional
public class bloodGroupServiceImpl implements bloodGroupService {
@Autowired
private BloodDao dao;
@Override
public void saveBloodGroup(BloodGroup bloodgroup) {
dao.save(bloodgroup);
}
public List<BloodGroup> allBloodGroup() {
return dao.listBloodGroup();
}
@Service("sectionService")
@Transactional
public class sectionServiceImpl implements sectionService{
@Autowired
private SectionDao dao;
@Override
public void save(Section section) {
dao.save(section);
}
@Override
public List<Section> allSection() {
return dao.allSection();
}
@Service("EmployeeService")
@Transactional
public class employeeServiceImpl implements employeeService{
@Autowired
private EmployeeDao dao;
@Autowired
private BloodDao bloodDao;
@Autowired
private SectionDao sectionDao;
@Override
public List<Employee> allEmployee() {
return dao.allEmployee();
}
@Override
public void save(Employee employee, int bloodgroup,int section) {
employee.setBloodgroup(bloodDao.findById(bloodgroup));
employee.setSection(sectionDao.findById(section));
dao.save(employee);
}
}
@Controller
@RequestMapping("/")
public class AppController {
@Autowired
employeeService wService;
@RequestMapping(value = { "/employee-list" }, method = RequestMethod.GET)
public String listWaheeb(ModelMap model) {
model.addAttribute("loggedinuser", getPrincipal());
List<Employee> emp = wService.allEmployee();
model.addAttribute("empList", emp);
return "allEmployee";
}
}
@控制器
@请求映射(“/”)
公共类AppController{
@自动连线
员工服务;
@RequestMapping(值={“/员工列表”},方法=RequestMethod.GET)
公共字符串listWaheeb(模型映射模型){
addAttribute(“loggedinuser”,getPrincipal());
List emp=wService.allEmployee();
model.addAttribute(“empList”,emp);
返回“所有员工”;
}
}
allEmployee.jsp
<div class="content">
<table id="mytable">
<tbody>
<c:forEach items="${empList}" var="eList">
<tr>
<td>${eList.wid}</td>
<td>${eList.wname}</td>
<!-- for BloodGroup and Section fields-->
</tr>
</c:forEach>
</tbody>
</table>
</div>
${eList.wid}
${eList.wname}
我的查询是
选择employee.wname、bloodgroup.blood\u name、section.sname
来自员工、血液集团、部门
其中employee.bidd=bloodgroup.bid
和employee.sidd=section.sid
和employee.wname='abc'
如何在hibernate条件中编写此命令以返回列表显示您的存储库和您拥有的内容tried@HithamS.AlQadheeb:请再次检查我的代码,并帮助我的员工添加一个按姓名获取员工的方法。然后,只需添加fetch=FetchType.LAZY即可在员工中显示您的存储库和您拥有的内容tried@Hithams.AlQadheeb:请再次检查我的代码,并帮助我的员工添加一个方法来按姓名获取员工。然后,只需将fetch=FetchType.LAZY添加到员工中的section和bloodgroup