Convert json array of arrays to some Java representation using Jackson - java

I am trying to convert following jsonString structure to a Java list/array of objects:
[
[1,21940000,1905386136,null,"KR","akshay","04/06/2017","03/06/2017",2017,9,40,"JPY",7478,"JPY",7478,"WHT (Residen",null,0,"03/06/2017","03/06/2017","20170604",null],
[2,21940000,1903732187,null,"KR",null,"06/06/2017","05/06/2017",2017,9,40,"JPY",608547485,"JPY",608547485,"WHT (Non-Resi",null,0,"05/06/2017","05/06/2017","20170606",null],
[3,21940000,2001898163, ............... ]
.
.
.
.
.
.
.
.
]
Below is Java code:
ObjectMapper mapper = new ObjectMapper();
MyData[][] data = mapper.readValue(jsonString, MyData[][].class);
But, I get following error:
com.fasterxml.jackson.databind.JsonMappingException:
Can not construct instance of com.org.model.MyData:
no String-argument constructor/factory method to deserialize from String value ('KR')
at [Source: java.io.StringReader#1327cf05; line: 1, column: 30] (through reference chain: java.lang.Object[][0]->java.lang.Object[][4])
Can someone help me out please? Thanks
EDIT: Below is my POJO MyData.java code:
#Entity
#Table(schema = "My_Schema", name = "My_Data_Table")
#SuppressFBWarnings(value = { "EI_EXPOSE_REP", "EI_EXPOSE_REP2" }, justification = "I prefer to suppress these FindBugs warnings")
public class MyData implements Serializable {
/**
*
*/
private static final long serialVersionUID = -6936461726389768288L;
public MyData() {
super();
}
/**
* #param id
*/
public MyData(Long id) {
super();
this.id = id;
}
#Id
private Long id;
#Column(name = "ACCOUNT")
private long account;
#Column(name = "DOC_NUMBER")
private long docNumber;
#Column(name = "TYPE")
private String type;
#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
#Column(name = "DOC_DATE")
private Date docDate;
#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
#Column(name = "POSTING_DATE")
private Date postingDate;
#Column(name = "YEAR")
private long year;
#Column(name = "PERIOD")
private long period;
#Column(name = "PK")
private long pk;
#Column(name = "TAX_CODE")
private String taxCode;
#Column(name = "CCY")
private String ccy;
#Column(name = "DOC_CCY_AMT")
private long docCcyAmt;
#Column(name = "LOCAL_CCY")
private String localCcy;
#Column(name = "LOCAL_CCY_AMT")
private long localCcyAmt;
#Column(name = "TEXT")
private String text;
#Column(name = "DOC_HEADER_TEXT")
private String docHeaderText;
#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
#Column(name = "CLEARING_DATE")
private Date clearingDate;
#Column(name = "CLEARING_DOC")
private long clearingDoc;
#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
#Column(name = "ENTRY_DATE")
private Date entryDate;
#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
#Column(name = "VALUE_DATE")
private Date valueDate;
#Column(name = "ASSIGNMENT")
private String assignment;
#Column(name = "REMARKS")
private String remarks;
// Getters and setters to follow .....
So, the thing is my input JSON string is an array of arrays and I want it to be in some Java representation be it an ArrayList or plain Array...

You are probably missing required attributes for "KR" in your "MyData" class. Until you post definition for MyData class here, take a look at this code. It will surely help you.
class Student {
private String name;
private int age;
public Student(){}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String toString(){
return "Student [ name: "+name+", age: "+ age+ " ]";
}
}
and to test it
import java.io.IOException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
public class JacksonTester {
public static void main(String args[]){
ObjectMapper mapper = new ObjectMapper();
String jsonString = "{\"name\":\"Mahesh\", \"age\":21}";
//map json to student
try{
Student student = mapper.readValue(jsonString, Student.class);
System.out.println(student);
mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT);
jsonString = mapper.writeValueAsString(student);
System.out.println(jsonString);
}
catch (JsonParseException e) { e.printStackTrace();}
catch (JsonMappingException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
}
}

Related

Spring Boot Data JpaSpecificationExecutor couldn't retrieve data by date time

This is my entity class:
#Data
#Entity
#Table(name = "CHECKS")
public class ChecksEntity implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime beginDate;
private Long checkId;
private String courtName;
private LocalDateTime createdDate = LocalDateTime.now();
private String dateOfBirth;
private LocalDateTime decisionDate;
private String decisionNumber;
private LocalDateTime endDate;
private String filePath;
private String judgeName;
private String name;
private String note;
private String patronymic;
private String person;
private String personType;
private String responseData;
private String surname;
}
and this is my JpaSpecificationExecutor class:
#Component
public class ChecksSpecification {
public Specification<ChecksEntity> getChecks(ArchiveOperationRequestDto request) {
return (root, query, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
if (request.getPerson() != null && !request.getPerson().isEmpty()) {
predicates.add(criteriaBuilder.equal(root.get("person"), request.getPerson()));
}
if (request.getDecisionNumber() != null && !request.getDecisionNumber().isEmpty()) {
predicates.add(criteriaBuilder.equal(root.get("decisionNumber"), request.getDecisionNumber()));
}
if (request.getCourtName() != null && !request.getCourtName().isEmpty()) {
predicates.add(criteriaBuilder.equal(root.get("courtName"), request.getCourtName()));
}
if (request.getToDate() != null || request.getFromDate() != null) {
// predicates.add(criteriaBuilder.equal(root.get("beginDate"), request.getToDate()));
// predicates.add(criteriaBuilder.equal(root.get("beginDate"), request.getFromDate()));
final Predicate created = criteriaBuilder.equal(root.get("beginDate"), request.getToDate());
return criteriaBuilder.or(created);
}
return criteriaBuilder.or(predicates.toArray(new Predicate[0]));
};
}
}
When I send a request here, it returns data as normal in response, according to all the values I have specified.
This is my send request dto:
#Data
public class ArchiveOperationRequestDto {
private String person;
private String decisionNumber;
private LocalDateTime toDate;
private LocalDateTime fromDate;
private String courtName;
}
It just doesn't return data about toDate and fromDate. It comes empty. What should I do to return data from database by date?

JPA/Hibernate - Object does not save to the database

#Service
#Transactional
#RequiredArgsConstructor
public class HTMLParser {
public static final String link1;
public static final String link2;
public final String url;
private final #NonNull VillageRepository;
public void parseLink(String link, String selektor){
// 1. úroven - získej z hlavního odkazu všechny obce nutné k proklikání
try {
Document doc = Jsoup.connect(link).get();
Elements links = doc.select(selektor);
for (Element alink : links) {
System.out.println("text: " + alink.text());
parseLink(vytvořURL(alink.attr("href")), "div.sloupec3 a");
}
if(links.isEmpty()){
links = doc.select("dl.sloupec dd");
Village village = extractInformation(links);
obecRepository.saveAndFlush(obec);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void parseLink(String link, String selektor){
try {
Document doc = Jsoup.connect(link).get();
Elements links = doc.select(selektor);
for (Element alink : links) {
parseLink(createURL(alink.attr("href")), "div.sloupec3 a");
}
if(links.isEmpty()){
links = doc.select("h4.navigace a");
Set<String> hiearchie = extractHiearchy(links);
Iterator<String> iterator = hiearchie.iterator();
links = doc.select("dl.sloupec dd");
Village village = extractInfo(links);
villageRepository.saveAndFlush(village );
}
} catch (IOException e) {
e.printStackTrace();
}
}
private Village extractInfo(Elements elements){
if(elements.size() != 13){
elements.add(3, new Element("<dd><span class=\"sede\">--- ---</span></dd>"));
}
Village village = new Village(Long.parseLong(elements.get(7).text()), elements.get(0).text(), elements.get(1).text(),
elements.get(2).text(), elements.get(3).text(), elements.get(5).text(), elements.get(6).text(),
elements.get(8).text(), getHours(elements.last()));
village.setEmails(extrahjZBloku(elements.get(9)));
village.setWWW(extrahjZBloku(elements.get(10)));
village.setPhones(extrahujTelefony(elements.get(11)));
village.setAccounts(extrahujÚčetAIBAN(elements.get(4)));
return village;
}
#Entity
#Getter
#Setter
public class Village {
public Village (){}
#Id
private long code;
#Column
private String type;
#Column(name = "name")
private String name;
#Column
private String adress;
#Column(name = "sec_adress")
private String secAdress;
#Column(name = "bank")
private String bank1;
#Column(name = "bankovní_spojení2")
private String bank2;
#Column
private String IBAN1;
#Column
private String IBAN2;
#Column
private String IC;
#Column
private String DIC;
#Column
private String shortcut;
#Column
private String email1;
#Column
private String email2;
#Column
private String email3;
#Column
private String email4;
#Column
private String www1;
#Column
private String www2;
#Column
private String www3;
#Column
private String www4;
#Column
private String telefon1;
#Column
private String telefon2;
#Column
private String telefon3;
#Column
private String telefon4;
#Lob
#Column(name = "hours")
private String hours;
}
public interface VillageRepository extends JpaRepository<Village, Long> {
}
My problem is that object village in the method parseLink does not save to the database... nothing happens and not even error shows up... When I try to save that object in the main method with with test parameters, it works, but not where I need... When I try to save something different in that method, nothing also happens, so the problem must be in the method parseHTML i guess
Thanks for help
PS: In intelij, i can see created insert command which seems to OK, but nothing is in the database...
Try putting the #Transactional annotation on the public functions, instead of the class.
I do not know how you really distributed into classes, but is it your JpaRepository decorated with the annotation #Repository ??

how to fetch data from two tables in JPA

I am not able to fetch all records from two tables using the below query
I have tried this but I am getting a result from one table only. I want a result of both the tables i.e, client_software_param_mapping and client_file_configuration having the same ClientId which is a foreign key from third pojo(client_software_configuration) to first and second pojo.
public Result showClientConfiguration() {EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("defaultPU");
EntityManager entityManager = entityManagerFactory.createEntityManager();
Query q=entityManager.
createQuery("SELECT c FROM client_software_param_mapping c JOIN fetch client_file_configuration f ON c.ClientId=f.ClientId");
List data =q.getResultList();
return ok(Json.toJson(data));
}
first pojo
#Entity
public class client_file_configuration {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String sourceFolder;
private String sourceFile;
private String processingFolder;
private String processingFile;
private String processedFolder;
private int intervalInMin;
private String readAfterDelay;
private String parserClass;
private String directoryMode;
private String fileMode;
private String actionMode;
private String type;
private String fileExpressionResolver;
#OneToOne
#JoinColumn(name = "ClientId")
private client_software_configuration clientSoftwareConfiguration;
public client_software_configuration getClientSoftwareConfiguration() {
return clientSoftwareConfiguration;
}
public void setClientSoftwareConfiguration(client_software_configuration clientSoftwareConfiguration) {
this.clientSoftwareConfiguration = clientSoftwareConfiguration;
}
}
secondpojo
#Entity
public class client_software_param_mapping {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String paramKey;
private String paramValue;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getParamKey() {
return paramKey;
}
public void setParamKey(String paramKey) {
this.paramKey = paramKey;
}
public String getParamValue() {
return paramValue;
}
public void setParamValue(String paramValue) {
this.paramValue = paramValue;
}
#ManyToOne
#JoinColumn(name = "ClientId")
private client_software_configuration clientSoftwareConfiguration;
public client_software_configuration getClientSoftwareConfiguration() {
return clientSoftwareConfiguration;
}
public void setClientSoftwareConfiguration(client_software_configuration clientSoftwareConfiguration) {
this.clientSoftwareConfiguration = clientSoftwareConfiguration;
}
}
thirdpojo
#Entity
public class client_software_configuration {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String url;
private int port;
private String endPoint;
private String isPost;
private String isPing;
private String params;
private int serialNo;
private String dateFormat;
private String token;
}
this is the right query as it is returning the object of the third pojo present at that ClientId so it is able to understand the type of ClientId.JPQL never uses table and column names. It always uses entity names and their mapped fields/properties names.so here I have taken the object of the third pojo having the ClientId field.
select c,p from client_file_configuration c,client_software_param_mapping p where c.clientSoftwareConfiguration = p.clientSoftwareConfiguration

delete entity foreign key relationship springs

I have two tables in a relationship with each other.
When I delete a line of data in the parent table.
If the data stream that is used in the table, the error message.
If not, to delete data
SQL Server Foreign Key Update and Delete Rules
No Action : Not allowed. Error message would be generated. (I want to use this exception)
Delete row in Ma_DM_NGAN_HANG throw Exception
#Entity
#Table(name = "Ma_DM_NGAN_HANG", schema = "dbo", uniqueConstraints = #UniqueConstraint(columnNames = "MANH"))
public class DmNganHang implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
// Fields
private Long id;
private String manh;
private String tennh;
private String tentat;
private String diachi;
private String dienthoai;
private String fax;
private String email;
private String taikhoan;
private String masothue;
private Integer idDonvi;
private String website;
private String filter;
private List<DmNhanVien> dmNhanViens = new ArrayList<DmNhanVien>();
private List<DmDoiTacTknganhang> dmDoiTacTknganhangs = new ArrayList<DmDoiTacTknganhang>();
// Constructors
/** default constructor */
public DmNganHang() {
}
/** minimal constructor */
public DmNganHang(Long id, String manh, String tennh, String taikhoan) {
this.id = id;
this.manh = manh;
this.tennh = tennh;
this.taikhoan = taikhoan;
}
/** full constructor */
public DmNganHang(Long id, String manh, String tennh, String tentat,
String diachi, String dienthoai, String fax, String email,
String taikhoan, String masothue, Integer idDonvi, String website,
String filter, List<DmNhanVien> dmNhanViens,
List<DmDoiTacTknganhang> dmDoiTacTknganhangs) {
this.id = id;
this.manh = manh;
this.tennh = tennh;
this.tentat = tentat;
this.diachi = diachi;
this.dienthoai = dienthoai;
this.fax = fax;
this.email = email;
this.taikhoan = taikhoan;
this.masothue = masothue;
this.idDonvi = idDonvi;
this.website = website;
this.filter = filter;
this.dmNhanViens = dmNhanViens;
this.dmDoiTacTknganhangs = dmDoiTacTknganhangs;
}
// Property accessors
#Id
#Column(name = "ID", unique = true, nullable = false, precision = 18, scale = 0)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
// Code ......
#JsonInclude(JsonInclude.Include.NON_EMPTY)
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "dmNganHang")
public List<DmNhanVien> getDmNhanViens() {
return this.dmNhanViens;
}
public void setDmNhanViens(List<DmNhanVien> dmNhanViens) {
this.dmNhanViens = dmNhanViens;
}
#JsonInclude(JsonInclude.Include.NON_EMPTY)
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "dmNganHang")
public List<DmDoiTacTknganhang> getDmDoiTacTknganhangs() {
return this.dmDoiTacTknganhangs;
}
public void setDmDoiTacTknganhangs(
List<DmDoiTacTknganhang> dmDoiTacTknganhangs) {
this.dmDoiTacTknganhangs = dmDoiTacTknganhangs;
}
}
#Entity
#Table(name = "Ma_DM_NHAN_VIEN", schema = "dbo", uniqueConstraints = #UniqueConstraint(columnNames = {
"MANV", "IdDonvi" }))
public class DmNhanVien implements java.io.Serializable {
// Fields
/**
*
*/
private static final long serialVersionUID = 1L;
private Long id;
private DmNganHang dmNganHang;
private DmPhongBan dmPhongBan;
private String manv;
private String tennv;
private String diachi;
private String hkthuongtru;
private String dienthoai;
private String masothue;
private String socmt;
private Date ngaycap;
private String noicap;
private Boolean canhancutru;
private String nhom;
private String taikhoannh;
private String tinhtranghonnhan;
private Boolean gioitinh;
private Date ngaysinh;
private Integer idDonvi;
private String filter;
private List<TnChungtuthunhap> tnChungtuthunhaps = new ArrayList<TnChungtuthunhap>();
private List<TnNguoiphuthuoc> tnNguoiphuthuocs = new ArrayList<TnNguoiphuthuoc>();
private List<DmHopDong> dmHopDongs = new ArrayList<DmHopDong>();
// Constructors
/** default constructor */
public DmNhanVien() {
}
/** minimal constructor */
public DmNhanVien(Long id, DmNganHang dmNganHang, DmPhongBan dmPhongBan,
String manv, String tennv, String diachi, String taikhoannh) {
this.id = id;
this.dmNganHang = dmNganHang;
this.dmPhongBan = dmPhongBan;
this.manv = manv;
this.tennv = tennv;
this.diachi = diachi;
this.taikhoannh = taikhoannh;
}
/** full constructor */
public DmNhanVien(Long id, DmNganHang dmNganHang, DmPhongBan dmPhongBan,
String manv, String tennv, String diachi, String hkthuongtru,
String dienthoai, String masothue, String socmt, Date ngaycap,
String noicap, Boolean canhancutru, String nhom, String taikhoannh,
String tinhtranghonnhan, Boolean gioitinh, Date ngaysinh,
Integer idDonvi, String filter,
List<TnChungtuthunhap> tnChungtuthunhaps,
List<TnNguoiphuthuoc> tnNguoiphuthuocs, List<DmHopDong> dmHopDongs) {
this.id = id;
this.dmNganHang = dmNganHang;
this.dmPhongBan = dmPhongBan;
this.manv = manv;
this.tennv = tennv;
this.diachi = diachi;
this.hkthuongtru = hkthuongtru;
this.dienthoai = dienthoai;
this.masothue = masothue;
this.socmt = socmt;
this.ngaycap = ngaycap;
this.noicap = noicap;
this.canhancutru = canhancutru;
this.nhom = nhom;
this.taikhoannh = taikhoannh;
this.tinhtranghonnhan = tinhtranghonnhan;
this.gioitinh = gioitinh;
this.ngaysinh = ngaysinh;
this.idDonvi = idDonvi;
this.filter = filter;
this.tnChungtuthunhaps = tnChungtuthunhaps;
this.tnNguoiphuthuocs = tnNguoiphuthuocs;
this.dmHopDongs = dmHopDongs;
}
// Property accessors
#Id
#Column(name = "ID", unique = true, nullable = false, precision = 18, scale = 0)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
#JsonIgnore
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "ID_NGANHANG", nullable = false)
public DmNganHang getDmNganHang() {
return this.dmNganHang;
}
public void setDmNganHang(DmNganHang dmNganHang) {
this.dmNganHang = dmNganHang;
}
#JsonIgnore
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "ID_PHONGBAN", nullable = false)
public DmPhongBan getDmPhongBan() {
return this.dmPhongBan;
}
// Code .....
}
Method Delete
public <T, E extends Serializable> void delete(T entity) {
entity = entityManager.merge(entity);
entityManager.remove(entity);
}
public <T, E extends Serializable> void deletefindOne(T entity) {
E id = (E) CommonUtil.invoke(entity, "getId");
JpaRepository repository = new SimpleJpaRepository(entity.getClass(),
entityManager);
repository.delete(repository.findOne(id));
}
Thanks

JPA Eclipselink error inserting into table

So first a bit of back story. The issue I am having is when I create a user. Previously I had tried to create a user and assign them a role separately before discovering that by inserting into the SEC_USER_ROLE table the program was also inserting into the APP_USER table and I was getting an error about inserting duplicate values into the parent table. However, now by creating the user and role together I am getting the following error:
Primary key should be primitive (or list of primitives for composite
pk) , an instance of java.lang.Long with the primary keys filled in or
an instance of WebIntSecRole.......
Code as follows, not sure where I'm goin g wrong or the best solution at this point.
Admin.java:
//New User Creation
WebIntUser newUser = new WebIntUser();
newUser.setLoginId(newLoginName);
newUser.setCreatedBy(loggedUser);
newUser.setCreatedOn(today);
newUser.setDbAuth(true);
newUser.setDeleted(false);
newUser.setDisabled(false);
newUser.setEmail(newEmail);
newUser.setEncrypted(true);
newUser.setEncryptPassword(true);
newUser.setFirstName(newFirstName);
newUser.setLastName(newLastName);
newUser.setUpdatedBy(loggedUser);
newUser.setUpdatedOn(today);
newUser.setVersion(1);
newUser.setLdapId(1);
//userService.createUser(newUser);
//Set role for new user
WebIntSecRoleUser newUserRole = new WebIntSecRoleUser();
newUserRole.setUser(newUser);
newUserRole.setDeleted(false);
newUserRole.setRole(userService.selectRoleById(1));
//newUserRole.setCreatedBy(loggedUser);
//newUserRole.setCreatedOn(today);
//newUserRole.setUpdatedBy(loggedUser);
//newUserRole.setUpdatedOn(today);
newUserRole.setVersionNumber(0);
userService.createRole(newUserRole);
WebIntUser.java
#Entity
#Table(name = "APP_USER")
#EntityListeners(value = { AuditChangeListener.class })
public class WebIntUser implements Serializable {
public WebIntUser() {
};
public WebIntUser(String login, String pass) {
this.loginId = login;
this.password = pass;
}
private Integer userId;
private String loginId;
private String password;
private String firstName;
private String lastName;
private String email;
private boolean disabled;
private boolean deleted;
private boolean dbAuth;
private boolean isEncrypted;
private boolean encryptPassword;
private Date lastLogin;
private Date prevLogin;
private Integer version;
private Date lastPasswordChange;
private Date createdOn;
private Date updatedOn;
private String createdBy;
private String updatedBy;
private Integer ldapId;
public static interface propertyName {
String userId = "userId";
String loginId = "loginId";
String password = "password";
String firstName = "firstName";
String lastName = "lastName";
String email = "email";
String disabled = "disabled";
String deleted = "deleted";
String dbAuth = "dbAuth";
String isEncrypted = "isEncrypted";
String encryptPassword = "encryptPassword";
String lastLogin = "lastLogin";
String prevLogin = "prevLogin";
String version = "version";
String lastPasswordChange = "lastPasswordChange";
String createdOn = "createdOn";
String updatedOn = "updatedOn";
String createdBy = "createdBy";
String updatedBy = "updatedBy";
String ldapId = "ldapId";
}
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "USER_ID", nullable = false)
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
.....getters/setters
}
WebIntSecRoleUser.java:
#Entity
#Table(name = "SEC_ROLE_USER")
#EntityListeners(value = {AuditInfoChangeListener.class})
public class WebIntSecRoleUser implements AuditableDomainObject {
private Long id;
private WebIntSecRole role;
private WebIntUser user;
private boolean deleted;
private AuditInfo auditInfo;
private long versionNumber;
private Date createdOn;
private Date updatedOn;
private String createdBy;
private String updatedBy;
public interface propertyName extends Auditable.propertyName {
String id="id";
String role="role";
String user="user";
String deleted = "deleted";
String createdOn = "createdOn";
String updatedOn = "updatedOn";
String createdBy = "createdBy";
String updatedBy = "updatedBy";
}
public static interface permissionKey{
String UPDATE="SecRoleUser.U";
}
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name = "ROLE_USER_ID",nullable = false, unique = true)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
#JoinColumn(name="ROLE_ID", nullable=false)
public WebIntSecRole getRole() {
return role;
}
public void setRole(WebIntSecRole role) {
this.role = role;
}
#ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
#JoinColumn(name="USER_ID", nullable = false)
public WebIntUser getUser() {
return user;
}
public void setUser(WebIntUser user) {
this.user = user;
}
Getters/setters
}
Note: There is some commented out code that I'm either trying not to use anymore, or in the case of Created By and Created On etc I was getting errors for multiple inserts.
In my opinion you have missed the #ManyToOne mapping on the WebIntSecRole. You only specified the #JoinColumn.
#ManyToOne(/* desired options */)
#JoinColumn(name="ROLE_ID", nullable=false)
public WebIntSecRole getRole() {
return role;

Categories

Resources