I develop application with Google App Engine and Google Cloud SQL
I am writing data in to Google Cloud SQL in Hebrew the data is written as "????"
how can I transform it to UTF-8
Thank you
example of entity
package com.darimpo.shared.entities;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.darimpo.shared.utilities.Utilities.Parameters;
#Entity
#Table(name = "AddressesTable")
public class Address extends Base {
private long buildingId;
private long floorId;
private long apartmentId;
private long userId;
#Transient
private String floorName;
#Transient
private String apartmentName;
public Address() {
}
public Address(long buildingId) {
setBuildingId(buildingId);
}
public Address(long buildingId,long floorId) {
this(buildingId);
setFloorId(floorId);
}
public Address(long buildingId,long floorId,long longId) {
this(buildingId,floorId);
setApartmentId(apartmentId);
}
public Address(Parameters parameters) {
super(parameters);
setUserId(parameters.getLong(USER_ID));
setBuildingId(parameters.getLong(BUILDING_ID));
setFloorId(parameters.getLong(FLOOR_ID));
setApartmentId(parameters.getLong(APARTMENT_ID));
setFloorName(parameters.getString(FLOOR_NAME));
setApartmentName(parameters.getString(APARTMENT_NAME));
}
#Override
protected void onCopy(Base source) {
super.onCopy(source);
if(source instanceof Address){
Address address = (Address)source;
setBuildingId(address.getBuildingId());
setFloorId(address.getFloorId());
setApartmentId(address.getApartmentId());
setFloorName(address.getFloorName());
setApartmentName(address.getApartmentName());
}
}
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public long getBuildingId() {
return buildingId;
}
public void setBuildingId(long buildingId) {
this.buildingId = buildingId;
}
public long getFloorId() {
return floorId;
}
public void setFloorId(long floorId) {
this.floorId = floorId;
}
public long getApartmentId() {
return apartmentId;
}
public void setApartmentId(long apartmentId) {
this.apartmentId = apartmentId;
}
public String getFloorName() {
return floorName;
}
public void setFloorName(String floorName) {
this.floorName = floorName;
}
public String getApartmentName() {
return apartmentName;
}
public void setApartmentName(String apartmentName) {
this.apartmentName = apartmentName;
}
public boolean isFullAddress() {
return buildingId != NO_ID && floorId != NO_ID && apartmentId != NO_ID;
}
#Override
public boolean equals(Object obj) {
if(obj instanceof Address){
Address address = (Address)obj;
if(getUserId() == address.getUserId()){
return getBuildingId() == address.getBuildingId() &&
getFloorId() == address.getFloorId() &&
getApartmentId() == address.getApartmentId();
}
}
return super.equals(obj);
}
public static final String BUILDING_ID = "buildingId";
public static final String USER_ID = "userId";
public static final String FLOOR_ID = "floorId";
public static final String APARTMENT_ID = "apartmentId";
public static final String FLOOR_NAME = "floorName";
public static final String APARTMENT_NAME = "apartmentName";
}
example of how I insert entity
public Base insert(Base base){
EntityManager em = entityManagerFactory.createEntityManager();
try{
em.getTransaction().begin();
base.setLastUpdated(getCoreServer().getTimeManager().getCurrentTime().getTime());
em.persist(base);
em.getTransaction().commit();
return base;
}
finally{
em.close();
}
}
example of how I select entity
public Object select(DarimpoQuery selectQuery){
EntityManager em = entityManagerFactory.createEntityManager();
try{
em.getTransaction().begin();
Query query =
em.createQuery(selectQuery.createSelectQuery());
addParametersQuery(selectQuery, query);
}
Object result = query.getResultList();
if(selectQuery.isSingleResult() && result instanceof List){
List<Object> results = (List)result;
return results.isEmpty() ? null : results.get(0);
}
return result;
}finally{
em.close();
}
}
After selecting an entity from dataBase I get the String as "????"
you can see how entity saved in dataBase on this link
https://drive.google.com/open?id=0B5FQ_6n1BT1EUnVFVFJsRFlyVTg
again thank you
Related
I have created a spring boot project with mongodb , when i insert data into collection it get inserted but when i try to fetch from findOne by id the inserted value based on id it always returns null, I have given my model class and inserting method below,please tell me whats wrong
Account.java
#Document(collection = "account")
public class Account {
#Id
private long _id;
#Field("account_name")
private String accountName;
#Field("connector_type")
private String connectorType;
#Field("xsiURI1")
private String xsiURI1;
#Field("xsiURI2")
private String xsiURI2;
#Field("oci1")
private String OCI1;
#Field("oci2")
private String OCI2;
#Field("telcomadmin_username")
private String telcomadminUsername;
#Field("telcomadmin_password")
private String telcomadminPassword;
#Field("password_expdays")
private String passwordExpdays;
#Field("account_email_address")
private String accountEmailAddress;
#DateTimeFormat(iso = ISO.DATE_TIME)
#Field("inserted_date")
private Date insertedDate;
#DateTimeFormat(iso = ISO.DATE_TIME)
#Field("updated_date")
private Date updatedDate;
#Field("isActive")
private Boolean isActive;
public long get_id() {
return _id;
}
public void set_id(long _id) {
this._id = _id;
}
public String getXsiURI1() {
return xsiURI1;
}
public void setXsiURI1(String xsiURI1) {
this.xsiURI1 = xsiURI1;
}
public String getXsiURI2() {
return xsiURI2;
}
public void setXsiURI2(String xsiURI2) {
this.xsiURI2 = xsiURI2;
}
public String getOCI1() {
return OCI1;
}
public void setOCI1(String oCI1) {
OCI1 = oCI1;
}
public String getOCI2() {
return OCI2;
}
public void setOCI2(String oCI2) {
OCI2 = oCI2;
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public String getConnectorType() {
return connectorType;
}
public void setConnectorType(String connectorType) {
this.connectorType = connectorType;
}
public String getTelcomadminUsername() {
return telcomadminUsername;
}
public void setTelcomadminUsername(String telcomadminUsername) {
this.telcomadminUsername = telcomadminUsername;
}
public String getTelcomadminPassword() {
return telcomadminPassword;
}
public void setTelcomadminPassword(String telcomadminPassword) {
this.telcomadminPassword = telcomadminPassword;
}
public String getPasswordExpdays() {
return passwordExpdays;
}
public void setPasswordExpdays(String passwordExpdays) {
this.passwordExpdays = passwordExpdays;
}
public String getAccountEmailAddress() {
return accountEmailAddress;
}
public void setAccountEmailAddress(String accountEmailAddress) {
this.accountEmailAddress = accountEmailAddress;
}
public Date getInsertedDate() {
return insertedDate;
}
public void setInsertedDate(Date insertedDate) {
this.insertedDate = insertedDate;
}
public Date getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(Date updatedDate) {
this.updatedDate = updatedDate;
}
public Boolean getIsActive() {
return isActive;
}
public void setIsActive(Boolean isActive) {
this.isActive = isActive;
}
}
AccountsController.java
#RestController
#RequestMapping("/accounts")
#CrossOrigin("*")
public class AccountsController {
#Autowired
AccountsRepository accountsRepository;
#Autowired
SequenceRepository sequenceRepository;
private static final String ACCOUNT_SEQ_KEY = "accountsequence";
#PostMapping("/create")
public Account createAccount(#Valid #RequestBody Account account) {
account.set_id(sequenceRepository.getNextSequenceId(ACCOUNT_SEQ_KEY));
account.setIsActive(true);
return accountsRepository.save(account);
}
#GetMapping(value = "/findByID/{id}")
public ResponseEntity<Account> getAccountById(#PathVariable("id") String id) {
Account account = accountsRepository.findOne(id);
if (account == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} else {
return new ResponseEntity<>(account, HttpStatus.OK);
}
}
}
AccountsRepository
public interface AccountsRepository {
List<Account> findAll(Sort sortByCreatedAtDesc);
Account save(Account account);
Account findOne(String id);
void delete(String id);
}
AccountsRepositoryIMPL
#Repository
public class AccountsRepositoryImpl implements AccountsRepository {
DBOperations dbOperations = new DBOperations();
#Override
public List<Account> findAll(Sort sortByCreatedAtDesc) {
Query q = new Query().with(new Sort(Sort.Direction.ASC, "inserted_date"));
List<Account> accountList = dbOperations.getMongoOpertion().findAllAndRemove(q, Account.class);
return accountList;
}
#Override
public Account save(Account account) {
try {
dbOperations.getMongoOpertion().save(account);
} catch (Exception e) {
e.printStackTrace();
}
return account;
}
#Override
public Account fin**strong text**dOne(String id) {
Account account = dbOperations.getMongoOpertion().findOne(Query.query(Criteria.where("_id").is(id)),
Account.class, "account");
return account;
}
#Override
public void delete(String id) {
Query query = new Query();
query.addCriteria(Criteria.where("id").is(id));
Account account = dbOperations.getMongoOpertion().findOne(query, Account.class);
dbOperations.getMongoOpertion().remove(account);
}
}
DBOperations.java
public class DBOperations {
ApplicationContext ctx = new GenericXmlApplicationContext("SpringConfig.xml");
public MongoOperations getMongoOpertion() {
MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
return mongoOperation;
}
}
Look at your code.
You have declared _id as Long type.
#Id
private long _id;
But in your below methods you are passing String id to match the criteria.
So it is not working.
#Override
public Account findOne(String id) {
Account account = dbOperations.getMongoOpertion().findOne(Query.query(Criteria.where("_id").is(id)),
Account.class, "account");
return account;
}
#Override
public void delete(String id) {
Query query = new Query();
query.addCriteria(Criteria.where("id").is(id));
Account account = dbOperations.getMongoOpertion().findOne(query, Account.class);
dbOperations.getMongoOpertion().remove(account);
}
Hi guys i'me having troubles using morphia for mongodb this is what im creating.
Im creating a spigot plugin for my hub server and im using mongodb with morphia for store my user object to my collection and this object only store 1 user instead of saving all users into the collection.
My user object
#Entity(value = "clientdata", noClassnameStored = true)
public class ClientData {
#Id
public int id;
#Indexed(options = #IndexOptions(unique = true))
private String uuid;
#Indexed
private String lastName, username, lastLoginDate, ip;
#Indexed
private int level, exp, joins, coins, pearls;
#Property("hats")
private List<Integer> hatsOwned;
public ClientData(){
this.hatsOwned = new ArrayList<>();
if(this.hatsOwned.isEmpty()){
this.hatsOwned.add(0);
}
}
public int getId() {
return id;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public void setId(int id) {
this.id = id;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getExp() {
return exp;
}
public void setExp(int exp) {
this.exp = exp;
}
public int getJoins() {
return joins;
}
public void setJoins(int joins) {
this.joins = joins;
}
public void addJoins(int joins) {
this.joins += joins;
}
public int getCoins() {
return coins;
}
public void setCoins(int coins) {
this.coins = coins;
}
public int getPearls() {
return pearls;
}
public void setPearls(int pearls) {
this.pearls = pearls;
}
public List<Integer> getHatsOwned() {
return hatsOwned;
}
public void setHatsOwned(List<Integer> hatsOwned) {
this.hatsOwned = hatsOwned;
}
public void addNewHatOwned(int hatID){
this.hatsOwned.add(hatID);
}
public String getLastLoginDate() {
return lastLoginDate;
}
public void setLastLoginDate(String lastLoginDate) {
this.lastLoginDate = lastLoginDate;
}
}
My mongo manager class
public class MongoManager {
private static MongoManager ins = new MongoManager();
private MongoClient mc;
private Morphia morphia;
private Datastore datastore;
private ClientDAO userDAO;
public static MongoManager get() {
return ins;
}
public void init() {
ServerAddress addr = new ServerAddress("127.0.0.1", 27017);
List<MongoCredential> credentials = new ArrayList<>();
credentials.add(MongoCredential.createCredential("union", "admin", "union16".toCharArray()));
mc = new MongoClient(addr, credentials);
morphia = new Morphia();
morphia.map(ClientData.class);
datastore = morphia.createDatastore(mc, "admin");
datastore.ensureIndexes();
userDAO = new ClientDAO(ClientData.class, datastore);
}
public void disconnect(){
this.mc.close();
}
public ClientData getUserByPlayer(Player player) {
ClientData du = userDAO.findOne("uuid", player.getUniqueId().toString());
long time = System.currentTimeMillis();
if (du == null) {
du = new ClientData();
du.setUuid(player.getUniqueId().toString());
du.setCoins(0);
du.setExp(0);
du.setJoins(0);
du.setLastLoginDate(DateFormat.getTimeInstance().format(time));
du.setLevel(0);
du.setPearls(0);
du.setIp(player.getAddress().getAddress().toString());
du.setUsername(player.getDisplayName());
du.setLastName(player.getName());
du.setHatsOwned(null);
userDAO.save(du);
}
return du;
}
public void saveUser(ClientData user) {
userDAO.save(user);
}
public List<ClientData> getAllUsers() {
return userDAO.find().asList();
}
}
You can't insert more than one because you have duplicateKey: you can't use an #id with primitive type without setting a unique value yourself.
You defined your id like this:
#Id
public int id;
Even though you never set any value for id, primitive types are initialized to 0, so you end up trying to insert multiple documents with the same key.
Solution:
You can either :
change your id to String: #Id String id;
change your id to ObjectId: #Id ObjectId id;
keep #Id int id and manually set a unique value to it (player.getUniqueId() for instance).
The first 2 options will work because they won't be initialized and will be null. Mongo will then generate a unique id for you.
I have an entity question and an entity test with ManyToMany relationship between the two entitie.
when I want to view the questions of a test this error is occurred.
failed to lazily initialize a collection of role:
tn.esen.entities.Test.questions, could not initialize proxy - no Session
this is the JPA implementation of the two entities.
Question:
package tn.esen.entities;
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.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
#Entity
public class Question implements Serializable {
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((contenu == null) ? 0 :
contenu.hashCode());
result = prime * result + ((dateCreation == null) ? 0 :
dateCreation.hashCode());
result = prime * result + ((niveauDeDifficulte == null) ? 0 :
niveauDeDifficulte.hashCode());
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Question other = (Question) obj;
if (contenu == null) {
if (other.contenu != null)
return false;
} else if (!contenu.equals(other.contenu))
return false;
if (dateCreation == null) {
if (other.dateCreation != null)
return false;
} else if (!dateCreation.equals(other.dateCreation))
return false;
if (niveauDeDifficulte == null) {
if (other.niveauDeDifficulte != null)
return false;
} else if (!niveauDeDifficulte.equals(other.niveauDeDifficulte))
return false;
return true;
}
/**
*
*/
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="id_question")
private int id;
private String contenu;
private String niveauDeDifficulte;
private Date dateCreation;
#OneToMany(mappedBy="question",fetch = FetchType.EAGER)
private Collection <Reponse> reponses;
#ManyToOne
private Categorie categorie;
#ManyToOne
private Administrateur administrateur;
#ManyToMany(mappedBy = "questions",fetch = FetchType.EAGER)
private Collection<Test> tests;
public Question(){
super();
}
#Override
public String toString() {
return "Question [id=" + id + ", contenu=" + contenu + ",
niveauDeDifficulte=" + niveauDeDifficulte + "]";
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getContenu() {
return contenu;
}
public void setContenu(String contenu) {
this.contenu = contenu;
}
public String getNiveauDeDifficulte() {
return niveauDeDifficulte;
}
public void setNiveauDeDifficulte(String niveauDeDifficulte) {
this.niveauDeDifficulte = niveauDeDifficulte;
}
public Date getDateCreation() {
return dateCreation;
}
public void setDateCreation(Date dateCreation) {
this.dateCreation = dateCreation;
}
public Collection<Reponse> getReponses() {
return reponses;
}
public void setReponses(Collection<Reponse> reponses) {
this.reponses = reponses;
}
public Categorie getCategorie() {
return categorie;
}
public void setCategorie(Categorie categorie) {
this.categorie = categorie;
}
public Administrateur getAdministrateur() {
return administrateur;
}
public void setAdministrateur(Administrateur administrateur) {
this.administrateur = administrateur;
}
public Collection<Test> getTest() {
return tests;
}
public void setTest(Collection<Test> tests) {
this.tests = tests;
}
public Question(String contenu, String niveauDeDifficulte, Date
dateCreation) {
super();
this.contenu = contenu;
this.niveauDeDifficulte = niveauDeDifficulte;
this.dateCreation = dateCreation;
}
Test:
package tn.esen.entities;
#Entity
public class Test implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String duree;
private String typeDePreparation;
private String lieu;
private int nbrQuestionFacile;
private int nbrQuestionMoyen;
private int nbrQuestionDifficle;
#OneToMany(mappedBy = "test")
private Collection<Resultat> resultats;
#ManyToMany
private Collection<Question> questions;
#ManyToOne
private ResponsableTechnique responsableTechnique;
public Test() {
super();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDuree() {
return duree;
}
public void setDuree(String duree) {
this.duree = duree;
}
public Collection<Question> getQuestions() {
return questions;
}
public void setQuestions(Collection<Question> questions) {
this.questions = questions;
}
public Test(String duree, String typeDePreparation, String lieu, int
nbrQuestionFacile, int nbrQuestionMoyen,
int nbrQuestionDifficle) {
super();
this.duree = duree;
this.typeDePreparation = typeDePreparation;
this.lieu = lieu;
this.nbrQuestionFacile = nbrQuestionFacile;
this.nbrQuestionMoyen = nbrQuestionMoyen;
this.nbrQuestionDifficle = nbrQuestionDifficle;
}
public ResponsableTechnique getRésponsableTechnique() {
return responsableTechnique;
}
public void setRésponsableTechnique(ResponsableTechnique
résponsableTechnique) {
this.responsableTechnique = résponsableTechnique;
}
public String getTypeDePreparation() {
return typeDePreparation;
}
public void setTypeDePreparation(String typeDePreparation) {
this.typeDePreparation = typeDePreparation;
}
public String getLieu() {
return lieu;
}
public void setLieu(String lieu) {
this.lieu = lieu;
}
public int getNbrQuestionFacile() {
return nbrQuestionFacile;
}
public void setNbrQuestionFacile(int nbrQuestionFacile) {
this.nbrQuestionFacile = nbrQuestionFacile;
}
public int getNbrQuestionMoyen() {
return nbrQuestionMoyen;
}
public void setNbrQuestionMoyen(int nbrQuestionMoyen) {
this.nbrQuestionMoyen = nbrQuestionMoyen;
}
public int getNbrQuestionDifficle() {
return nbrQuestionDifficle;
}
public void setNbrQuestionDifficle(int nbrQuestionDifficle) {
this.nbrQuestionDifficle = nbrQuestionDifficle;
}
public Collection<Resultat> getResultats() {
return resultats;
}
public void setRésultats(Collection<Resultat> resultats) {
this.resultats = resultats;
}
}
}
When you get Test and access Test.questions later, after leaving the transaction, you will get a lazy initialization exception when the Test entity is detached and questions has not been initialized/fetched yet. You can either do a specific fetch, or depending on your configuration, you can call Test.getQuestions().size() before you exit the transaction.
References: How to solve lazy initialization exception using JPA and Hibernate as provider
LazyInitializationException in JPA and Hibernate
Hibernate LazyInitializationException using Spring CrudRepository
Spring:version 3.2.9
Hibernate:version 4.2.19
BaseDaoImpl.java
public class BaseDaoImpl<T> implements BaseDao<T> {
public SessionFactory sessionFactory;
protected Class<T> entityClass;
#Override
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public Session getSession(){
return sessionFactory.getCurrentSession();
}
#SuppressWarnings({ "unchecked", "rawtypes" })
public BaseDaoImpl() {
Class c = getClass();
Type type = c.getGenericSuperclass();
if (type instanceof ParameterizedType) {
Type[] parameterizedType = ((ParameterizedType) type).getActualTypeArguments();
this.entityClass = (Class<T>) parameterizedType[0];
}
}
#Resource(name="sessionFactory")
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
#Override
public boolean save(T entity) {
try {
getSession().save(entity);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
#Override
public boolean delete(T entity) {
try {
getSession().delete(entity);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
#Override
public boolean update(T entity) {
try {
getSession().update(entity);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
#SuppressWarnings("unchecked")
#Override
public T get(Integer id) {
return (T) getSession().get(entityClass, id);
}
#SuppressWarnings("unchecked")
#Override
public List<T> findByIdSet(Integer[] ids) {
Criteria criteria=getSession().createCriteria(entityClass);
criteria.add(Restrictions.in("id", ids));
return (List<T>)criteria.list();
}
#SuppressWarnings("unchecked")
#Override
public List<T> findAllList() {
return getSession().createCriteria(entityClass).list();
}
#SuppressWarnings("unchecked")
#Override
public Pager findByPager(Pager pager) {
Criteria criteria=getSession().createCriteria(entityClass);
criteria.setProjection(Projections.rowCount());
int totalCount = ((Long) criteria.uniqueResult()).intValue();
pager.setTotalCount(totalCount);
criteria.setProjection(null);
pager.init();
criteria.setFirstResult((pager.getPageIndex()-1)*pager.getPageSize());
criteria.setMaxResults(pager.getPageSize());
List<T> te =(List<T>)criteria.list();
pager.setDatas((List<T>)criteria.list());
return pager;
}
}
Pager.java
import java.util.List;
public class Pager {
private int pageSize;
private int pageIndex;
private int totalCount;
private int totalPage;
private List<?> datas;
private boolean hasNextPage;
private boolean hasPreviousPage;
public void init(){
pageIndex=1;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getPageIndex() {
return pageIndex;
}
public void setPageIndex(int pageIndex) {
this.pageIndex = pageIndex;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List<?> getDatas() {
return datas;
}
public void setDatas(List<?> datas) {
this.datas = datas;
}
public boolean isHasNextPage() {
return hasNextPage;
}
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}
public boolean isHasPreviousPage() {
return hasPreviousPage;
}
public void setHasPreviousPage(boolean hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}
}
Entity:Student.java
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
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 javax.persistence.Temporal;
import javax.persistence.TemporalType;
#Entity
#Table(name="student")
public class Student {
private int stu_id;
private String stu_name;
private String stu_password;
private Department department;
private Major major;
private String stu_sex;
private String stu_per_sig;
private String stu_head_img;
private Date stu_regist_time;
private String stu_attn_crs_ids;
private String stu_pw_question;
private String stu_pw_answer;
public Student() {
}
public Student(int stu_id, String stu_name, String stu_password,
Department department, Major major, String stu_sex,
String stu_per_sig, String stu_head_img, Date stu_regist_time,
String stu_attn_crs_ids, String stu_pw_question,
String stu_pw_answer) {
this.stu_id = stu_id;
this.stu_name = stu_name;
this.stu_password = stu_password;
this.department = department;
this.major = major;
this.stu_sex = stu_sex;
this.stu_per_sig = stu_per_sig;
this.stu_head_img = stu_head_img;
this.stu_regist_time = stu_regist_time;
this.stu_attn_crs_ids = stu_attn_crs_ids;
this.stu_pw_question = stu_pw_question;
this.stu_pw_answer = stu_pw_answer;
}
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
public int getStu_id() {
return stu_id;
}
public void setStu_id(int stu_id) {
this.stu_id = stu_id;
}
#Column(length=20,nullable=false)
public String getStu_name() {
return stu_name;
}
public void setStu_name(String stu_name) {
this.stu_name = stu_name;
}
#Column(length=20,nullable=false)
public String getStu_password() {
return stu_password;
}
public void setStu_password(String stu_password) {
this.stu_password = stu_password;
}
#Column(length=2,nullable=false)
public String getStu_sex() {
return stu_sex;
}
public void setStu_sex(String stu_sex) {
this.stu_sex = stu_sex;
}
#Column(length=255,nullable=true)
public String getStu_per_sig() {
return stu_per_sig;
}
public void setStu_per_sig(String stu_per_sig) {
this.stu_per_sig = stu_per_sig;
}
#Column(length=255,nullable=false)
public String getStu_head_img() {
return stu_head_img;
}
public void setStu_head_img(String stu_head_img) {
this.stu_head_img = stu_head_img;
}
#Temporal(value=TemporalType.TIMESTAMP)
#Column(nullable=false)
public Date getStu_regist_time() {
return stu_regist_time;
}
public void setStu_regist_time(Date stu_regist_time) {
this.stu_regist_time = stu_regist_time;
}
#Column(length=255,nullable=true)
public String getStu_attn_crs_ids() {
return stu_attn_crs_ids;
}
public void setStu_attn_crs_ids(String stu_attn_crs_ids) {
this.stu_attn_crs_ids = stu_attn_crs_ids;
}
#Column(length=64,nullable=false)
public String getStu_pw_question() {
return stu_pw_question;
}
public void setStu_pw_question(String stu_pw_question) {
this.stu_pw_question = stu_pw_question;
}
#Column(length=64,nullable=false)
public String getStu_pw_answer() {
return stu_pw_answer;
}
public void setStu_pw_answer(String stu_pw_answer) {
this.stu_pw_answer = stu_pw_answer;
}
#ManyToOne()
#JoinColumn(name="stu_dept_id",nullable=false)
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
#ManyToOne()
#JoinColumn(name="stu_major_id",nullable=false)
public Major getMajor() {
return major;
}
public void setMajor(Major major) {
this.major = major;
}
}
I write BaseDaoImpl.java to implement the interface BaseDao.java
When I debug the project ,I found that the size of te list is 0 .
In findByPager method of BaseDaoImpl.java.
Why the method criteria.list() return a empty list?
Why is it not a List<Student> list ?
It puzzles me a long time.I'm a fresh man,who can help me to solve this problem.
The problem of your code is this line:
Criteria criteria=getSession().createCriteria(entityClass);
Because when you use criteria queries, you are building a query against a reference of a particular persistent class and your variable entityClass isn't.
protected Class<T> entityClass;
The correct way to build a criteria query is:
Criteria criteria=getSession().createCriteria(Entity.class);
Then you need to change that line of your code. You need to add the .class to your variable:
Criteria criteria=getSession().createCriteria(entityClass.class);
I share you some links about criteria queries.
https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/Criteria.html
https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html
I hope this information helps you.
Good luck.
I've been stuck here for almost a week trying find the answer on the internet but sadly nothing worked. :( Everytime I try to update using this method:
private Tenant updateTenantWithApplicationProperties(List<TenantApplicationProperty> newTenantApplicationProperties, String tenantId) {
String reason = "Update application properties.";
Tenant existingTenant = tenantRepository.findById(tenantId);
List<TenantApplicationProperty> temp = existingTenant.getTenantApplicationProperties();
existingTenant.setTenantApplicationProperties(newTenantApplicationProperties);
setApplicationPropertiesUpdateValues(temp, existingTenant);
if(newTenantApplicationProperties != null && newTenantApplicationProperties.size() != 0) {
Tenant savedTenantWithAppProps = saveTenantWithLog(existingTenant, reason);
return savedTenantWithAppProps;
}
return existingTenant;
}
Im always getting this error:
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.infor.ecom.tenant.manager.model.entity.ApplicationProperty
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1295)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:876)
But when Im using this method it works fine:
public Tenant updateTenant(Tenant tenant) {
List<Database> databases = tenant.getDatabases();
List<Administrator> administrators = tenant.getAdministrators();
validateUpdateTenant(tenant);
validateDatabases(databases);
validateAdministrators(administrators);
Tenant existingTenant = findByIdWithAllDetails(tenant.getId());
List<Database> listExistingDatabases = existingTenant.getDatabases();
Database existingEcomDb = getDatabaseByType(listExistingDatabases,
TenantManagerConstants.ECOM_DATASOURCE);
setDatabaseUpdateValues(listExistingDatabases, tenant);
setAdministratorsUpdateValues(existingTenant.getAdministrators(),
tenant);
setProductUpdateValue(existingTenant.getProduct(), tenant);
setApplicationPropertiesUpdateValues(existingTenant.getTenantApplicationProperties(), tenant);
setEcomDBParamsDefaultValues(tenant);
setAdministratorDefaultValues(tenant);
Database updateEcomDb = getDatabaseByType(tenant.getDatabases(),
TenantManagerConstants.ECOM_DATASOURCE);
Boolean shouldInstallNewDB = true;
if (existingEcomDb.getName().equalsIgnoreCase(updateEcomDb.getName())
&& existingEcomDb.getHost().equalsIgnoreCase(
updateEcomDb.getHost())
&& existingEcomDb.getPort().equals(updateEcomDb.getPort())) {
shouldInstallNewDB = false;
} else {
testEcomDBConnection(updateEcomDb);
}
int ecomDbTableCount = getEcomDBTableCount(updateEcomDb);
String[][] languages = formatAndValidateLanguages(updateEcomDb
.getEcomDatabaseParameters().getLanguages());
Tenant updatedTenant = saveExistingTenant(tenant);
if (updatedTenant != null) {
if (shouldInstallNewDB || ecomDbTableCount == 0) {
installDatabase(updateEcomDb, languages, updatedTenant);
} else {
updateDatabase(updateEcomDb, languages, updatedTenant);
}
storageService.updateTenantFolderStructure(updatedTenant);
} else {
throw new TenantManagerException(
ApiMessageConstants.M_TENANT_PROVISION_ERROR,
ApiMessageConstants.C_TENANT_PROVISION_ERROR);
}
return updatedTenant;
}
So here is my complete codes:
Tenant.java
package com.infor.ecom.tenant.manager.model.entity;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import com.infor.ecom.tenant.manager.constant.TenantManagerConstants;
import com.infor.ecom.tenant.manager.constant.TenantStatusEnum;
#Entity
#Table(name="tenant")
#XmlRootElement(name = "Tenant",namespace = "http://com.infor.ecom.tenant.manager/Tenant")
public class Tenant extends BaseModel {
private static final long serialVersionUID = -6687293822212120396L;
#Id
private String id;
private String displayName;
private String description;
private String url;
private String apiKey;
private String status;
#OneToMany(mappedBy = "tenant", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
private List<Database> databases;
#OneToMany(mappedBy = "tenant", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Activity> activites;
#OneToMany(mappedBy = "tenant", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Administrator> administrators;
private String message;
#OneToMany(mappedBy = "tenant", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<TenantApplicationProperty> tenantApplicationProperties;
#OneToOne(mappedBy = "tenant", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private Product product;
public Database findEcomDatabase() {
Database database = null;
if(databases != null) {
for(Database db : databases) {
if(db.getDatasource() != null) {
if(TenantManagerConstants.ECOM_DATASOURCE.equals(db.getDatasource().getName())) {
database = db;
break;
}
}
}
}
return database;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getStatus() {
return status;
}
public void setStatus(TenantStatusEnum statusEnum) {
this.status = statusEnum.name();
}
public List<Database> getDatabases() {
return databases;
}
public void setDatabases(List<Database> databases) {
this.databases = databases;
}
public void addDatabase(Database database) {
if (this.databases == null) {
this.databases = new ArrayList<Database>();
}
database.setTenant(this);
this.databases.add(database);
}
public List<Activity> getActivites() {
return activites;
}
public void setActivites(List<Activity> activities) {
this.activites = activities;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setStatus(String status) {
this.status = status;
}
public List<Administrator> getAdministrators() {
return this.administrators;
}
public void setAdministrators(List<Administrator> administrators) {
for (Administrator admin:administrators) {
admin.setTenant(this);
}
this.administrators = administrators;
}
public void addAdministrator(Administrator administrator) {
if (this.administrators == null) {
this.administrators = new ArrayList<Administrator>();
}
administrator.setTenant(this);
this.administrators.add(administrator);
}
public List<TenantApplicationProperty> getTenantApplicationProperties() {
return tenantApplicationProperties;
}
public void setTenantApplicationProperties(
List<TenantApplicationProperty> tenantApplicationProperties) {
this.tenantApplicationProperties = tenantApplicationProperties;
}
public void addTenantApplicationProperty(TenantApplicationProperty tenantApplicationProperty) {
if (this.tenantApplicationProperties == null) {
this.tenantApplicationProperties = new ArrayList<TenantApplicationProperty>();
}
tenantApplicationProperty.setTenant(this);
this.tenantApplicationProperties.add(tenantApplicationProperty);
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
product.setTenant(this);
this.product = product;
}
}
TenantApplicationProperty.java
package com.infor.ecom.tenant.manager.model.entity;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import com.infor.ecom.tenant.manager.model.entity.pk.TenantApplicationPropertyPK;
#Entity
#Table(name = "tenant_application_property")
#IdClass(TenantApplicationPropertyPK.class)
public class TenantApplicationProperty extends BaseModel {
private static final long serialVersionUID = 1L;
#Id
#ManyToOne
#JoinColumn(name = "tenant_id")
private Tenant tenant;
#Id
#OneToOne
#JoinColumn(name = "application_property_id")
private ApplicationProperty applicationProperty;
private String value;
public TenantApplicationProperty() {
super();
}
/**
* Added constructor to handle custom query for
* findByTenantIdApplicationPropertyName. No need to retrieve Tenant and
* ApplicationProperty
*
* #param value
*/
public TenantApplicationProperty(String value) {
setTenant(null);
setApplicationProperty(null);
setValue(value);
}
public Tenant getTenant() {
return tenant;
}
public void setTenant(Tenant tenant) {
this.tenant = tenant;
}
public ApplicationProperty getApplicationProperty() {
return applicationProperty;
}
public void setApplicationProperty(ApplicationProperty applicationProperty) {
this.applicationProperty = applicationProperty;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime
* result
+ ((applicationProperty == null) ? 0 : applicationProperty
.hashCode());
return result;
}
#Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null)
return false;
if (getClass() != object.getClass())
return false;
TenantApplicationProperty tenantAppProp = (TenantApplicationProperty) object;
if (applicationProperty == null) {
if (tenantAppProp.applicationProperty != null) {
return false;
}
} else if (!applicationProperty.getApplicationPropertyGroup().getName().equals(tenantAppProp.applicationProperty.getApplicationPropertyGroup().getName())
|| !applicationProperty.getName().equals(tenantAppProp.applicationProperty.getName())) {
return false;
}
return true;
}
}
TenanatApplicationPropertyPK.java
package com.infor.ecom.tenant.manager.model.entity.pk;
public class TenantApplicationPropertyPK implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private String tenant;
private Integer applicationProperty;
public String getTenantId() {
return tenant;
}
public void setTenantId(String tenant) {
this.tenant = tenant;
}
public Integer getApplicationPropertyId() {
return applicationProperty;
}
public void setApplicationPropertyId(Integer applicationProperty) {
this.applicationProperty = applicationProperty;
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime
* result
+ ((applicationProperty == null) ? 0 : applicationProperty
.hashCode());
result = prime * result + ((tenant == null) ? 0 : tenant.hashCode());
return result;
}
#Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
TenantApplicationPropertyPK tenantAppPropPK = (TenantApplicationPropertyPK) obj;
if (applicationProperty == null) {
if (tenantAppPropPK.applicationProperty != null) {
return false;
}
} else if (!applicationProperty
.equals(tenantAppPropPK.applicationProperty)) {
return false;
}
if (tenant == null) {
if (tenantAppPropPK.tenant != null) {
return false;
}
} else if (!tenant.equals(tenantAppPropPK.tenant)) {
return false;
}
return true;
}
}
ApplicationProperty.java
package com.infor.ecom.tenant.manager.model.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
#Entity
#Table(name = "application_property")
public class ApplicationProperty extends BaseModel {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String defaultValue;
private boolean isVisible;
private boolean clientVisible;
#OneToOne
#JoinColumn(name = "property_group_id")
private ApplicationPropertyGroup applicationPropertyGroup;
#OneToOne
#JoinColumn(name = "property_type_id")
private ApplicationPropertyType applicationPropertyType;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
public boolean getIsVisible() {
return isVisible;
}
public void setIsVisible(boolean isVisible) {
this.isVisible = isVisible;
}
public boolean getClientVisible() {
return clientVisible;
}
public void setClientVisible(boolean clientVisible) {
this.clientVisible = clientVisible;
}
public ApplicationPropertyGroup getApplicationPropertyGroup() {
return applicationPropertyGroup;
}
public void setApplicationPropertyGroup(ApplicationPropertyGroup applicationPropertyGroup) {
this.applicationPropertyGroup = applicationPropertyGroup;
}
public ApplicationPropertyType getApplicationPropertyType() {
return applicationPropertyType;
}
public void setApplicationPropertyType(ApplicationPropertyType applicationPropertyType) {
this.applicationPropertyType = applicationPropertyType;
}
}
ApplicationPropertyGroup.java
package com.infor.ecom.tenant.manager.model.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "application_property_group")
public class ApplicationPropertyGroup extends BaseModel {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
ApplicationPropertyType.java
package com.infor.ecom.tenant.manager.model.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "application_property_type")
public class ApplicationPropertyType extends BaseModel {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
TenantServiceImpl.java
private Tenant updateTenantWithApplicationProperties(List<TenantApplicationProperty> newTenantApplicationProperties, String tenantId) {
String reason = "Update application properties.";
Tenant existingTenant = tenantRepository.findById(tenantId);
List<TenantApplicationProperty> temp = existingTenant.getTenantApplicationProperties();
existingTenant.setTenantApplicationProperties(newTenantApplicationProperties);
setApplicationPropertiesUpdateValues(temp, existingTenant);
if(newTenantApplicationProperties != null && newTenantApplicationProperties.size() != 0) {
Tenant savedTenantWithAppProps = saveTenantWithLog(existingTenant, reason);
return savedTenantWithAppProps;
}
return existingTenant;
}
private Tenant saveTenantWithLog(Tenant tenant, String reason) {
Tenant updatedTenant = tenantRepository.save(tenant);
TenantLog tenantLog = new TenantLog();
tenantLog.setTenantId(updatedTenant.getId());
tenantLog.setDisplayName(updatedTenant.getDisplayName());
tenantLog.setDescription(updatedTenant.getDescription());
tenantLog.setUrl(updatedTenant.getUrl());
tenantLog.setApiKey(updatedTenant.getApiKey());
tenantLog.setStatus(TenantStatusEnum.valueOf(updatedTenant.getStatus()));
tenantLog.setReason(reason);
tenantLog.setMessage(updatedTenant.getMessage());
tenantLogRepository.save(tenantLog);
return updatedTenant;
}
private void setApplicationPropertiesUpdateValues(List<TenantApplicationProperty> existingTenantAppProps, Tenant tenant) {
List<TenantApplicationProperty> newTenantApplicationProperties = (tenant.getTenantApplicationProperties() != null) ? tenant.getTenantApplicationProperties() : new ArrayList<TenantApplicationProperty>();
if(newTenantApplicationProperties.size() != 0) {
for(TenantApplicationProperty tenantAppProp : newTenantApplicationProperties) {
int index = existingTenantAppProps.indexOf(tenantAppProp);
if (index < 0) {
// throw an error -- tenantAppProp should always exist, right?
} else {
existingTenantAppProps.get(index).setValue(tenantAppProp.getValue());
}
}
tenant.setTenantApplicationProperties(existingTenantAppProps);
}
}
public Tenant updateTenant(Tenant tenant) {
List<Database> databases = tenant.getDatabases();
List<Administrator> administrators = tenant.getAdministrators();
validateUpdateTenant(tenant);
validateDatabases(databases);
validateAdministrators(administrators);
Tenant existingTenant = findByIdWithAllDetails(tenant.getId());
List<Database> listExistingDatabases = existingTenant.getDatabases();
Database existingEcomDb = getDatabaseByType(listExistingDatabases,
TenantManagerConstants.ECOM_DATASOURCE);
setDatabaseUpdateValues(listExistingDatabases, tenant);
setAdministratorsUpdateValues(existingTenant.getAdministrators(),
tenant);
setProductUpdateValue(existingTenant.getProduct(), tenant);
setApplicationPropertiesUpdateValues(existingTenant.getTenantApplicationProperties(), tenant);
setEcomDBParamsDefaultValues(tenant);
setAdministratorDefaultValues(tenant);
Database updateEcomDb = getDatabaseByType(tenant.getDatabases(),
TenantManagerConstants.ECOM_DATASOURCE);
Boolean shouldInstallNewDB = true;
if (existingEcomDb.getName().equalsIgnoreCase(updateEcomDb.getName())
&& existingEcomDb.getHost().equalsIgnoreCase(
updateEcomDb.getHost())
&& existingEcomDb.getPort().equals(updateEcomDb.getPort())) {
shouldInstallNewDB = false;
} else {
testEcomDBConnection(updateEcomDb);
}
int ecomDbTableCount = getEcomDBTableCount(updateEcomDb);
String[][] languages = formatAndValidateLanguages(updateEcomDb
.getEcomDatabaseParameters().getLanguages());
Tenant updatedTenant = saveExistingTenant(tenant);
if (updatedTenant != null) {
if (shouldInstallNewDB || ecomDbTableCount == 0) {
installDatabase(updateEcomDb, languages, updatedTenant);
} else {
updateDatabase(updateEcomDb, languages, updatedTenant);
}
storageService.updateTenantFolderStructure(updatedTenant);
} else {
throw new TenantManagerException(
ApiMessageConstants.M_TENANT_PROVISION_ERROR,
ApiMessageConstants.C_TENANT_PROVISION_ERROR);
}
return updatedTenant;
}
private Tenant saveExistingTenant(Tenant tenant) {
tenant.setStatus(TenantStatusEnum.INPROGRESS);
tenant.setMessage(ApiMessageConstants.M_DATABASE_UPDATE_INPROGRESS);
String reason = ApiMessageConstants.R_UPDATE_TENANT;
return saveTenantWithLog(tenant, reason);
}
In application property, you defined 1-1 relation like:
#OneToOne
#JoinColumn(name = "property_group_id")
private ApplicationPropertyGroup applicationPropertyGroup;
#OneToOne
#JoinColumn(name = "property_type_id")
private ApplicationPropertyType applicationPropertyType;
While you have not defined the same relation (note it should work bidirectionally i.e. say for e.g. if you as a person related to an employee id, then employee id is related to you as a person well) in individual property ApplicationPropertyGroup and ApplicationPropertyType.
You should add the same 1-1 relation in ApplicationPropertyGroup and ApplicationPropertyType with ApplicationProperty.