I have an error in class domain Microservice
Oracle dataBase
package hisL3.vnpt.tiepnhan.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import oracle.sql.DATE;
//import org.hibernate.annotations.Table;
import javax.persistence.Table;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Column;
import javax.persistence.Id;
#Entity
#Data
#AllArgsConstructor
#NoArgsConstructor
#Table(name = "his_manager.tgg_quanly_lichhen")
public class Dm_bao_hiem_y_te {
private Integer id;
private Integer id_lichhen;
private Integer mabenhnhan;
private String tenbenhnhan;
private Integer gioitinh;
private String sodienthoai;
private String tenbenhvien;
private Integer songay;
private DATE ngayhen;
private DATE ngaythaotac;
private Integer ngioithaotac;
private Integer guisms;
#Column(name = "ID_LICHHEN", insertable = false, updatable = false)
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId_lichhen() {
return id_lichhen;
}
public void setId_lichhen(Integer id_lichhen) {
this.id_lichhen = id_lichhen;
}
public Integer getMabenhnhan() {
return mabenhnhan;
}
public void setMabenhnhan(Integer mabenhnhan) {
this.mabenhnhan = mabenhnhan;
}
public String getTenbenhnhan() {
return tenbenhnhan;
}
public void setTenbenhnhan(String tenbenhnhan) {
this.tenbenhnhan = tenbenhnhan;
}
public Integer getGioitinh() {
return gioitinh;
}
public void setGioitinh(Integer gioitinh) {
this.gioitinh = gioitinh;
}
public String getSodienthoai() {
return sodienthoai;
}
public void setSodienthoai(String sodienthoai) {
this.sodienthoai = sodienthoai;
}
public String getTenbenhvien() {
return tenbenhvien;
}
public void setTenbenhvien(String tenbenhvien) {
this.tenbenhvien = tenbenhvien;
}
public Integer getSongay() {
return songay;
}
public void setSongay(Integer songay) {
this.songay = songay;
}
public DATE getNgayhen() {
return ngayhen;
}
public void setNgayhen(DATE ngayhen) {
this.ngayhen = ngayhen;
}
public DATE getNgaythaotac() {
return ngaythaotac;
}
public void setNgaythaotac(DATE ngaythaotac) {
this.ngaythaotac = ngaythaotac;
}
public Integer getNgioithaotac() {
return ngioithaotac;
}
public void setNgioithaotac(Integer ngioithaotac) {
this.ngioithaotac = ngioithaotac;
}
public Integer getGuisms() {
return guisms;
}
public void setGuisms(Integer guisms) {
this.guisms = guisms;
}
}
Error:
Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: hisL3.vnpt.tiepnhan.entity.Dm_bao_hiem_y_te column: id_lichhen (should be mapped with insert="false" update="false")
Connection oracle.jdbc.driver.T4CConnection#493325b4 marked as broken because of SQLSTATE(08006), ErrorCode(17002)
Related
> PurchaseOrderHeaderDto
package com.assignment.dto;
import java.util.List;
import com.assignment.entity.PurchaseItem;
public class PurchaseOrderHeaderDto{
private List<PurchaseItem> itemList;
public List<PurchaseItem> getItemList() {
return itemList;
}
public void setItemList(List<PurchaseItem> itemList) {
this.itemList = itemList;
}
public int getPonumber() {
return ponumber;
}
public void setPonumber(int ponumber) {
this.ponumber = ponumber;
}
public String getVendor() {
return vendor;
}
public void setVendor(String vendor) {
this.vendor = vendor;
}
public String getPaymentterms() {
return paymentterms;
}
public void setPaymentterms(String paymentterms) {
this.paymentterms = paymentterms;
}
public String getCompanycode() {
return companycode;
}
public void setCompanycode(String companycode) {
this.companycode = companycode;
}
private int ponumber;
private String vendor;
private String paymentterms;
private String status;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
private String companycode;
}
above is the code for the DTO class
> PurchaseOrderHeader
package com.assignment.entity;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import com.fasterxml.jackson.annotation.JsonBackReference;
#Entity
#Table(name="PurchaseOrderHeader")
/*#FilterDef(name ="poFilter", parameters =#ParamDef(name ="ponumber", type ="int"))
#Filter(name ="poFilter", condition ="ponumber>=:ponumber")
*/
public class PurchaseOrderHeader implements Serializable{
/**
*
*/
private static final long serialVersionUID = 2293787550626038248L;
#Id
#GenericGenerator(name = "generator", strategy = "increment")
#GeneratedValue(generator = "generator")
#Column(name="ponumber")
private int ponumber;
#JsonBackReference
#OneToMany( fetch = FetchType.EAGER,mappedBy = "purchaseorder",cascade = CascadeType.ALL)
private List<PurchaseItem> itemList;
public List<PurchaseItem> getItemList() {
return itemList;
}
public int getPonumber() {
return ponumber;
}
public void setPonumber(int ponumber) {
this.ponumber = ponumber;
}
public void setItemList(List<PurchaseItem> itemList) {
this.itemList = itemList;
}
public Integer getCompanycode() {
return companycode;
}
public void setCompanycode(Integer companycode)
{
this.companycode = companycode;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getVendor() {
return vendor;
}
public void setVendor(String vendor) {
this.vendor = vendor;
}
public String getPaymentterms() {
return paymentterms;
}
public void setPaymentterms(String paymentterms) {
this.paymentterms = paymentterms;
}
#Column(name="companycode")
private Integer companycode;
#Column(name="status")
private String status;
#Column(name="vendor")
private String vendor;
#Column(name="paymentterms")
private String paymentterms;
public PurchaseOrderHeader() {
}
public PurchaseOrderHeader(int ponumber, Integer companycode, String status, String vendor, String paymentterms) {
this.ponumber = ponumber;
this.companycode = companycode;
this.status = status;
this.vendor = vendor;
this.paymentterms = paymentterms;
}
}
above is the code for the DO class
model mapper mapping errors ,Unable to convert String to Integer
DTO class has company code as String and the DO class has the company code
as Integer type when data is passed in json if string value is passed
for company code it should throw 400 bad request error in postman.
NumberFormatException on passing data in postman.
Mysql database used for db transactions.
SEVERE: Servlet.service() for servlet [spring] in context with path [/Pro] threw exception [Request processing failed; nested exception is org.modelmapper.MappingException: ModelMapper mapping errors:
1) Converter org.modelmapper.internal.converter.NumberConverter#6279a752 failed to convert java.lang.String to java.lang.Integer.
1 error] with root cause
java.lang.NumberFormatException: For input string: "asdfghertyu"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
I have two Classes, Fount and Criterions, the first one is one to many and the other many to one. When i call delete i get the error mentioned in the title.
I tried a lot of solutions here in stackoverflow and other sites about the same problem, but i can't do it right, i'll be glad if someone find out
Solutions i tried:
Cascade - as you can see, i'm already using the annotation, and i tried a lot of different annotations that i found in the internet
Remove the object Criterion from the object Fount and then the Fount from the Criterion before deleting the Criterion from the database
Remove from Fount object and updating the database right after it
The error:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Cannot delete or update a parent row: a foreign key constraint fails
(mydb.fount_criterion, CONSTRAINT
FK5p3wsropwaokyta6cmy3edvcv FOREIGN KEY (criterions_id) REFERENCES
criterion (id))
my classes Fount and Criterion:
package br.com.engcon.entities;
import javax.persistence.*;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
#Entity
#Table(name = "fount")
//#SequenceGenerator(name="SEQUENCE", sequenceName="fount_id_seq")
public class Fount {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
#Column(nullable=false, name="url")
private String url;
#OneToMany(fetch = FetchType.LAZY, targetEntity = Criterion.class)
#Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE})
private List<Criterion> criterions;
//
// #OneToMany(fetch = FetchType.LAZY, targetEntity = Text.class, orphanRemoval = true)
// #Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE})
// private List<Text> texts;
#Column(nullable=false, name="isUsed")
private boolean isUsed = false;
#Column(nullable=false, name="isActive")
private boolean isActive = true;
#Column(nullable=false, name="isDeleted")
private boolean isDeleted = false;
public Fount(String url) throws URISyntaxException {
this.url = url;
this.criterions = new ArrayList<Criterion>();
new URI(url);
}
public Fount(String url, List<Criterion> criterions) {
this.url = url;
this.criterions = criterions != null? criterions : new ArrayList<Criterion>();
}
public Fount() {
this.criterions = new ArrayList<Criterion>();
}
public URI getURI() {
if(!url.isEmpty()) {
try {
return new URI(url);
} catch (URISyntaxException e) {
return null;
}
}
return null;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public List<Criterion> getCriterions() {
return criterions;
}
public void setCriterions(List<Criterion> criterions) {
this.criterions = criterions;
}
public void setUrl(String url) {
this.url = url;
}
public void addCriterions(List<Criterion> criterions){
this.criterions = this.criterions != null? this.criterions : new ArrayList<Criterion>();
this.criterions.addAll(criterions);
}
public void addCriterions(Fount fount) {
this.criterions = criterions != null? criterions : new ArrayList<Criterion>();
for(Criterion criterion : fount.getCriterions()) {
Criterion newCriterion = criterion.clone();
newCriterion.setFount(this);
criterions.add(newCriterion);
}
}
public Criterion addCriterion(Criterion criterion) {
this.criterions = criterions != null? criterions : new ArrayList<Criterion>();
Criterion newCriterion = criterion.clone();
newCriterion.setFount(this);
this.criterions.add(newCriterion);
return criterion;
}
public Criterion addCriterion(String criterionTxt) {
return this.addCriterion(new Criterion(criterionTxt));
}
public String getUrl() {
return this.url;
}
#Override
public String toString() {
return this.getUrl();
}
public boolean isUsed() {
return isUsed;
}
public void setUsed(boolean used) {
isUsed = used;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean active) {
isActive = active;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean isDeleted) {
this.isDeleted = isDeleted;
}
}
Criterion:
package br.com.engcon.entities;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
#Entity
#Table(name = "criterion")
//#SequenceGenerator(name="SEQUENCE", sequenceName="criterion_id_seq")
public class Criterion {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
#ManyToOne(fetch=FetchType.EAGER)
#OnDelete(action = OnDeleteAction.CASCADE)
#JoinColumn(name="fount_id", nullable=false)
private Fount fount;
#Column(nullable=true, name="word_filter")
private String word;
#Column(nullable=false, name="case_sensitive")
private boolean caseSensitive;
public Criterion() {
// TODO Auto-generated constructor stub
caseSensitive = false;
}
public Criterion(String word) {
this.word = word;
this.caseSensitive = false;
}
public Criterion(String word, boolean caseSensitive) {
this.word = word;
this.caseSensitive = caseSensitive;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getWord() {
return word;
}
#Override
public Criterion clone(){
return new Criterion(this.word, this.caseSensitive);
}
public void setWord(String word) {
this.word = word;
}
public boolean isCaseSensitive() {
return caseSensitive;
}
public void setCaseSensitive(boolean caseSensitive) {
this.caseSensitive = caseSensitive;
}
public Fount getFount() {
return fount;
}
public void setFount(Fount fount) {
this.fount = fount;
}
#Override
public String toString() {
return this.word;
}
}
You need to synchronize both end of the bidirectional association.
If you have only 1 bidirectional association (in your example - Criterion-Fount and Fount-Criterion), the following helper methods (for disassociating the parent from all child entities) would solve the problem:
public void addCriterion(Criterion criterion) {
criterions.add(comment);
criterion.setFount(this);
}
public void removeCriterion(Criterion criterion) {
criterions.remove(criterion);
criterion.setFount(null);
}
And make sure you're using cascading:
#OneToMany(mappedBy = "fount", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Criterion> criterions;
When I launch my Spring Hibernate App, I get this error :
Error creating bean with name 'manageUserDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory edusef.dao.ManageUserDAO.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SessionFactory' defined in ServletContext resource [/WEB-INF/application-context.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: edusef.model.Roles, at table: USER, for columns: [org.hibernate.mapping.Column(roles)]
I'm not a real guru on J2EE and this almost my first advanced app. I don't know what is happening there, here is my User and Roles models :
package edusef.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import java.util.Date;
#Entity
#Table (name="USER")
public class User {
private int idUser;
private String NomUser;
private String PrenUser;
private String MailUser;
private String AdressUser;
private int PhoneUser;
private Date DateNaissanceUser;
private int AccountStatus;
private String Password;
private String Login;
private char SexeUser;
private String ImagePath;
private int idRole;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name="IDUSER", unique = true, nullable = false)
public int getidUser() { return idUser; }
public void setidUser(int iduser) { this.idUser = iduser; }
#Column(name="NOMUSER", nullable = false)
public String getNomUser() { return NomUser; }
public void setNomUser(String nomUser) { this.NomUser = nomUser; }
#Column(name="PRENUSER", nullable = false)
public String getPrenUser() { return PrenUser; }
public void setPrenUser(String prenUser) { this.PrenUser = prenUser; }
#Column(name="MAILUSER", nullable = false)
public String getMailUser() { return MailUser; }
public void setMailUser(String mailUser) { this.MailUser = mailUser; }
#Column(name="ADRESSUSER", nullable = false)
public String getAdressUser() { return AdressUser; }
public void setAdressUser(String adressUser) { this.AdressUser = adressUser; }
#Column(name="PHONEUSER", nullable = false)
public int getPhoneUser() { return PhoneUser; }
public void setPhoneUser(int phoneUser) { this.PhoneUser = phoneUser; }
#Column(name="DATENAISSANCEUSER", nullable = false)
public Date getDateNaissanceUser() { return DateNaissanceUser; }
public void setDateNaissanceUser(Date dateNaissanceUser) { this.DateNaissanceUser = dateNaissanceUser; }
#Column(name="ACCOUNTSTATUS", nullable = false)
public int getAccountStatus() { return AccountStatus; }
public void setAccountStatus(int accountStatus) { this.AccountStatus = accountStatus; }
#Column(name="PASSWORD", nullable = false)
public String getPassword() { return Password; }
public void setPassword(String password) { this.Password = password; }
#Column(name="LOGIN", nullable = false)
public String getLogin() { return Login; }
public void setLogin(String login) { this.Login = login; }
#Column(name="SEXEUSER", nullable = false)
public char getSexeUser() { return SexeUser; }
public void setSexeUser(char sexeUser) { this.SexeUser = sexeUser; }
#Column(name="IMAGEPATH", nullable = true)
public String getImagePath() { return ImagePath; }
public void setImagePath(String imagePath) { this.ImagePath = imagePath; }
#ManyToOne(cascade = CascadeType.ALL)
#JoinColumn(name="IDROLE", nullable=false)
public int getidRole() { return idRole; }
public void setidRole(int idRole) { this.idRole = idRole; }
private Roles roles;
public Roles getRoles() {
return roles;
}
public void setRoles(Roles roles) {
this.roles = roles;
}
#Override
public String toString() {
StringBuffer strBuff = new StringBuffer();
strBuff.append("idUser : ").append(getidUser());
strBuff.append(", NomUser : ").append(getNomUser());
strBuff.append(", PrenUser : ").append(getPrenUser());
strBuff.append(", MailUser : ").append(getMailUser());
strBuff.append(", AdressUser : ").append(getAdressUser());
strBuff.append(", PhoneUser : ").append(getPhoneUser());
strBuff.append(", DateNaissanceUser : ").append(getDateNaissanceUser());
strBuff.append(", AccountStatus : ").append(getAccountStatus());
strBuff.append(", Password : ").append(getPassword());
strBuff.append(", Login : ").append(getLogin());
strBuff.append(", SexeUser : ").append(getSexeUser());
strBuff.append(", ImagePath : ").append(getImagePath());
// strBuff.append(", idRole : ").append(getidRole());
return strBuff.toString();
}
}
Roles :
package edusef.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table (name="ROLES")
public class Roles {
private int idRole;
private String Role;
#Id
#Column(name="IDROLE", unique = true, nullable = false)
public int getIdRole() { return idRole; }
public void setIdRole(int idRole) { this.idRole = idRole; }
#Column(name="ROLES", nullable = false)
public String getRole() { return Role; }
public void setRole(String role) { Role = role; }
}
ManageUserDAO :
package edusef.dao;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import edusef.model.User;
import java.util.List;
#Repository
public class ManageUserDAO {
public #interface ComponentScan {
}
#Autowired
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() { return sessionFactory; }
public void setSessionFactory(SessionFactory sessionFactory) {this.sessionFactory = sessionFactory;}
public void addUser(User user) {
getSessionFactory().getCurrentSession().save(user);
}
public void deleteUser(User user) {
getSessionFactory().getCurrentSession().delete(user);
}
public void updateUser(User user) {
getSessionFactory().getCurrentSession().update(user);
}
public User getUserById(int id) {
List list = getSessionFactory().getCurrentSession().createQuery("from User where id=?").setParameter(0, id).list();
return (User)list.get(0);
}
public List<User> getUsers() {
List list = getSessionFactory().getCurrentSession().createQuery("from User").list();
return list;
}
}
RolesDAOImpl :
public class RolesDAOImpl implements RolesDAO {
#Autowired
private SessionFactory sessionFactory;
private Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}
public Roles getRoles(int idRole) {
Roles role = (Roles) getCurrentSession().load(Roles.class, idRole);
return role;
}
}
My Logic is that each User has one Role (ManyToOne) and each role can be used by many users. the User.idRole entity should return the idRole of the User and depending on it we test the user role on Spring Security ..
Any help is welcome ! Thanks
You're trying to map an int with #ManyToOne in your User class. You should be mapping a Role instead.
Remove the getIdRole() and setIdRole() methods from this part, they don't belong there.
#ManyToOne(cascade = CascadeType.ALL)
#JoinColumn(name="IDROLE", nullable=false)
public int getidRole() { return idRole; }
public void setidRole(int idRole) { this.idRole = idRole; }
private Roles roles;
public Roles getRoles() {
return roles;
}
There are 2 table, Parent is MeetingTypes Child is Meetings they have1 : m mapping
Meeting has releaseID atribute so i want to filter its by releaseID .but problem is, its in Child Table...
If it is Parent Table we can do it simply and it is working
Query query = session.getCurrentSession().createQuery("from MeetingTypes where releaseID= :releaseID");
query.setParameter("releaseID", releaseID);
List list = query.list();
if(list!=null && list.size()>0){
return list;
}else{
return null;
}
I tried it this way
Query query = session.getCurrentSession().createSQLQuery(
"from MeetingTypes mt join mt.Meetings m " +
"where m.releaseID = :releaseID");
query.setParameter("releaseID", releaseID);
return query.list();
But give bellow Erro
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from MeetingTypes mt join mt.Meetings m where m.releaseID = 192' at
line 1
relevant tabales
package pearson.dashboard.model;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
#Entity
public class MeetingTypes {
#Id
#Column
#GeneratedValue(strategy=GenerationType.AUTO)
private int meetingTypeID;
#Column
private String typeName;
#OneToMany(mappedBy = "meetingTypes",fetch = FetchType.EAGER)
private List<Meetings> meetings;
public List<Meetings> getMeetings() {
return meetings;
}
public void setMeetings(List<Meetings> meetings) {
this.meetings = meetings;
}
public MeetingTypes() {
// TODO Auto-generated constructor stub
}
public MeetingTypes(int meetingTypeID, String typeName
) {
super();
this.meetingTypeID = meetingTypeID;
this.typeName = typeName;
}
public int getMeetingTypeID() {
return meetingTypeID;
}
public void setMeetingTypeID(int meetingTypeID) {
this.meetingTypeID = meetingTypeID;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
}
package pearson.dashboard.model;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.springframework.context.annotation.Lazy;
#Entity
public class Meetings {
#Id
#Column
#GeneratedValue(strategy=GenerationType.AUTO)
private int meetingID;
#Column
private Date sheduleTime;
#Column
private String meetingHeading;
#Column
private String comment;
#Column
private String roomName;
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "meetingTypeID")
private MeetingTypes meetingTypes;
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "releaseID")
private Releases releases;
public Releases getReleases() {
return releases;
}
public void setReleases(Releases releases) {
this.releases = releases;
}
public MeetingTypes getMeetingTypes() {
return meetingTypes;
}
public void setMeetingTypes(MeetingTypes meetingTypes) {
this.meetingTypes = meetingTypes;
}
public Meetings() {
// TODO Auto-generated constructor stub
}
public Meetings(int meetingID, Date sheduleTime, String meetingHeading,
String comment, String roomName) {
super();
this.meetingID = meetingID;
this.sheduleTime = sheduleTime;
this.meetingHeading = meetingHeading;
this.comment = comment;
this.roomName = roomName;
}
public int getMeetingID() {
return meetingID;
}
public void setMeetingID(int meetingID) {
this.meetingID = meetingID;
}
public Date getSheduleTime() {
return sheduleTime;
}
public void setSheduleTime(Date sheduleTime) {
this.sheduleTime = sheduleTime;
}
public String getMeetingHeading() {
return meetingHeading;
}
public void setMeetingHeading(String meetingHeading) {
this.meetingHeading = meetingHeading;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getRoomName() {
return roomName;
}
public void setRoomName(String roomName) {
this.roomName = roomName;
}
}
package pearson.dashboard.model;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
#Entity
public class Releases {
#Id
#Column
#GeneratedValue(strategy=GenerationType.AUTO)
private int releaseID;
#Column
private String orcleCode;
#Column
private String status;
#Column
private Date staging;
#Column
private Date cabCall;
#Column
private Date rrr;
#Column
private String remarks;
#Column
private String releaseName;
#Column
private Date prodDate;
#ManyToOne( fetch = FetchType.EAGER)
#JoinColumn(name = "teamID")
private Teams teams;
public Teams getTeams() {
return teams;
}
public void setTeams(Teams teams) {
this.teams = teams;
}
#OneToMany(mappedBy = "releases",fetch = FetchType.EAGER)
#Fetch(value = FetchMode.SUBSELECT)
private List<Meetings> meetings;
public List<Meetings> getMeetings() {
return meetings;
}
public void setMeetings(List<Meetings> meetings) {
this.meetings = meetings;
}
public Releases() {}
public Releases(int releasID, String orcleCode, String status,
Date staging, Date cabCall, Date rrr, String remarks,
String releaseName,Date prodDate) {
super();
this.releaseID = releasID;
this.orcleCode = orcleCode;
this.status = status;
this.staging = staging;
this.cabCall = cabCall;
this.rrr = rrr;
this.remarks = remarks;
this.releaseName = releaseName;
this.prodDate = prodDate;
}
public int getReleaseID() {
return releaseID;
}
public void setReleaseID(int releaseID) {
this.releaseID = releaseID;
}
public String getOrcleCode() {
return orcleCode;
}
public void setOrcleCode(String orcleCode) {
this.orcleCode = orcleCode;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Date getStaging() {
return staging;
}
public void setStaging(Date staging) {
this.staging = staging;
}
public Date getCabCall() {
return cabCall;
}
public void setCabCall(Date cabCall) {
this.cabCall = cabCall;
}
public Date getRrr() {
return rrr;
}
public void setRrr(Date rrr) {
this.rrr = rrr;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public String getReleaseName() {
return releaseName;
}
public void setReleaseName(String releaseName) {
this.releaseName = releaseName;
}
public Date getProdDate() {
return prodDate;
}
public void setProdDate(Date prodDate) {
this.prodDate = prodDate;
}
}
part of Controller******
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import pearson.dashboard.dto.NewMeeting;
import pearson.dashboard.service.MeetingService;
import pearson.dashboard.service.MeetingTypeService;
import pearson.dashboard.service.MemberService;
import pearson.dashboard.service.SwarmingScheduleService;
#Controller
public class MeetingTypesController {
#Autowired
private MeetingTypeService meetingTypeService;
//#Autowired
//private MeetingService meetingService;
#Autowired
private SwarmingScheduleService swarmingScheduleService;
#Autowired
private MemberService memberService;
#RequestMapping(value="/detailsPage",method=RequestMethod.POST)
public String getAllmeeting(#ModelAttribute NewMeeting newMeeting,BindingResult result,Map<String, Object> map){
int releaseID = newMeeting.getReleaseID();
map.put("meetingList", meetingTypeService.getAllMeetingTypes(releaseID));
map.put("swarmingScheduleList",swarmingScheduleService.gettAllSwarming() );
map.put("memberList",memberService.gettAllMembers() );
return "details";
}
}
You are using HQL not sql so in hql no keyword like join alternatively you can implement join using objecta.objectb and so on so you have to create your query like below
Query query = session.getCurrentSession().createQuery("FROM MeetingTypes mt WHERE mt.meetings.releases.id = :releaseID");
for more details see the below link
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html#queryhql-joins-forms
Your HQL query should be like this
Query query = session.getCurrentSession().createQuery("FROM MeetingTypes AS mt WHERE mt.meetings.releases.id = :releaseID");
query.setParameter("releaseID", releaseID);
return query.list();
hope this will solve your problem.
hopefully your Releases Entity something like
#Entity
#Table(name="meetings")
public class Meetings {
#Id
#Column(name="meetings_id")
#GeneratedValue(strategy=GenerationType.AUTO)
private int id;
//setter & getters
}
also you have not mentioned your name parameter in #Table() annotation is your table name is same as class name ?
#Entity
The #Entity annotation is used to mark this class as an Entity bean. So the class should atleast have a package scope no-argument constructor.
#Column
The #Column annotation is used to specify the details of the column to which a field or property will be mapped. If the #Column annotation is not specified by default the property name will be used as the column name.
#Table
The #Table annotation is used to specify the table to persist the data. The name attribute refers to the table name. If #Table annotation is not specified then Hibernate will by default use the class name as the table name.
createQuery() VS createSQLQuery()
createQuery()
Create a new instance of Query for the given HQL query string.
createSQLQuery()
Create a new instance of SQLQuery for the given SQL query string.
I have 2 Entity classes ParameterGroupBean and GroupLevelBean
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
#Entity
#Table(name="tbl_ParameterGroups")
public class ParameterGroupBean {
#Id
#GeneratedValue
private int ParameterGroupId;
private String ParameterGroupName;
private Boolean Status;
#ManyToOne
#JoinColumn(name="LevelId")
private GroupLevelBean level = new GroupLevelBean();
public GroupLevelBean getLevel() {
return level;
}
public void setLevel(GroupLevelBean level) {
this.level = level;
}
#Id
#GeneratedValue
public int getParameterGroupId() {
return ParameterGroupId;
}
public void setParameterGroupId(int parameterGroupId) {
ParameterGroupId = parameterGroupId;
}
#Column(length=120)
public String getParameterGroupName() {
return ParameterGroupName;
}
public void setParameterGroupName(String parameterGroupName) {
ParameterGroupName = parameterGroupName;
}
public Boolean getStatus() {
return Status;
}
public void setStatus(Boolean Status) {
this.Status = Status;
}
}
GroupLevelBean:
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
#Entity
#Table(name="tbl_GroupLevel")
public class GroupLevelBean {
private int LevelId;
private String LevelName;
#OneToMany(mappedBy = "level")
private Collection<ParameterGroupBean> parameterGroups = new ArrayList<ParameterGroupBean>();
public Collection<ParameterGroupBean> getParameterGroups() {
return parameterGroups;
}
public void setParameterGroups(Collection<ParameterGroupBean> parameterGroups) {
this.parameterGroups = parameterGroups;
}
#Id
#GeneratedValue
public int getLevelId() {
return LevelId;
}
public void setLevelId(int levelId) {
LevelId = levelId;
}
#Column(length = 30)
public String getLevelName() {
return LevelName;
}
public void setLevelName(String levelName) {
LevelName = levelName;
}
}
The relationship between GroupLevelBean and ParameterGroupBean is one to many.
I am getting an exception when i try to create a session object.
org.hibernate.MappingException: Could not determine type for: com.vrde.daems.bean.GroupLevelBean, at table: tbl_ParameterGroups, for columns: [org.hibernate.mapping.Column(level)]
Can anyone tell me what is the problem?
Because you are putting #Id and #GeneratedValue java persistence annotations above:
#Id
#GeneratedValue
private int ParameterGroupId;
and in same time above:
#Id
#GeneratedValue
public int getParameterGroupId() {
return ParameterGroupId;
}
Its enough just to put annotations above private int ParameterGroupId;