Create Dynamic JPA Query - java

I have a view with many fields as query filters, and I am using JPA derived queries , however creating all queries for every combination of fields/filters would be tedious and long.
I found out that I can create a dynamic query for it, but not sure how.
So far I have created these queries in my repository, but still need a lot more :
public interface EmployeeReportInfoViewRepository extends PagingAndSortingRepository<EmployeeReportInfo, Long> {
List<EmployeeReportInfo> findByControlNumber(String controlNmber);
List<EmployeeReportInfo> findByManager(String manager);
List<EmployeeReportInfo> findByofficeLocation(String officeLocation);
List<EmployeeReportInfo> findByBenchFlag(char benchFlag);
List<EmployeeReportInfo> findByBillableFlag(char billableFlag);
List<EmployeeReportInfo> findByEnableFlag(boolean enableFlag);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumber(String lastName, String firstName,String controlNumber);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumberAndManager(String lastName, String firstName,String controlNmber,String manager);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumberAndManagerAndOfficeLocation(String lastName, String firstName,String controlNmber,String manager,String officeLocation);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumberAndManagerAndOfficeLocationAndBenchFlag(String lastName, String firstName,String controlNmber,String manager,String officeLocation, char benchFlag);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumberAndManagerAndOfficeLocationAndBenchFlagAndBillableFlag(String lastName, String firstName,String controlNmber,String manager,String officeLocation, char benchFlag,char bllableFlag);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumberAndManagerAndOfficeLocationAndBenchFlagAndBillableFlagAndEnableFlagAndStartGreaterThanEqualAndEndLessThanEqual
(String lastName, String firstName,String controlNmber,String manager,String officeLocation, char benchFlag,char bllableFlag,
boolean emableFlag, Date start,Date end);
}
#Entity
#Table(name = "employee_report_view")
public class EmployeeReportInfo {
#Id
#Column(name = "employee_id")
private Long id;
private String name;
private Date start;
private Date end;
#Column(name = "control_number")
private String controlNumber;
#Column(name = "enable_flag")
private boolean enableFlag;
#Column(name = "billable_flag")
private char billableFlag;
#Column(name = "bench_flag")
private char benchFlag;
#Column(name = "office_location")
private String officeLocation;
#Column(name = "manager")
private String manager;
/**
* #return the id
*/
public Long getId() {
return id;
}
/**
* #return the name
*/
public String getName() {
return name;
}
/**
* #param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* #param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* #return the start
*/
public Date getStart() {
return start;
}
/**
* #param start the start to set
*/
public void setStart(Date start) {
this.start = start;
}
/**
* #return the end
*/
public Date getEnd() {
return end;
}
/**
* #param end the end to set
*/
public void setEnd(Date end) {
this.end = end;
}
/**
* #return the controlNumber
*/
public String getControlNumber() {
return controlNumber;
}
/**
* #param controlNumber the controlNumber to set
*/
public void setControlNumber(String controlNumber) {
this.controlNumber = controlNumber;
}
/**
* #return the enableFlag
*/
public boolean isEnableFlag() {
return enableFlag;
}
/**
* #param enableFlag the enableFlag to set
*/
public void setEnableFlag(boolean enableFlag) {
this.enableFlag = enableFlag;
}
/**
* #return the billableFlag
*/
public char getBillableFlag() {
return billableFlag;
}
/**
* #param billableFlag the billableFlag to set
*/
public void setBillableFlag(char billableFlag) {
this.billableFlag = billableFlag;
}
/**
* #return the benchFlag
*/
public char getBenchFlag() {
return benchFlag;
}
/**
* #param benchFlag the benchFlag to set
*/
public void setBenchFlag(char benchFlag) {
this.benchFlag = benchFlag;
}
/**
* #return the officeLocation
*/
public String getOfficeLocation() {
return officeLocation;
}
/**
* #param officeLocation the officeLocation to set
*/
public void setOfficeLocation(String officeLocation) {
this.officeLocation = officeLocation;
}
/**
* #return the manager
*/
public String getManager() {
return manager;
}
/**
* #param manager the manager to set
*/
public void setManager(String manager) {
this.manager = manager;
}
}

I can understand your needs:you want to dynamically generate query conditions based on the url issued by the form.Let's assume that the url maps to the back end to a HashMap<String,String>.
For instance,url:
127.0.0.1/employees?nameContains=jack&ageEquals=10
Map:
HashMap<String, String>:key:nameContains,value:jack,key:ageEuqals,value:10
The Spring framework can do this mapping automatically(RequestParamMapMethodArgumentResolver). What you need to do is to dynamically generate the Specification(Specification) by this map.
Gets the type of property corresponding to the field using reflect : name=>String, age=>Integer
Using CriteriaBuilder to build query criteria,it has comprehensive api,such as:
Predicate like(Expression x, String pattern); => contains
Predicate equal(Expression x, Expression y); => equal
Assemble your query criteria(or,and)
You get a Specification.
This is a relatively complex solution idea, which requires the coordination between the front table component and the back end, but it will be very convenient.
What I said is relatively simple and general, there are a lot of details.(such as nested properties,one-to-one,one-to-many,etc)
Also,You can have a look http://www.querydsl.com/

Related

Return List within List REST API Jax Rs

I am creating a REST API from java where I am returning an object list as follows:
#Path("/order")
public class OrderService implements IService
{
#Override
public Response get()
{
List<DataObj> list = new ArrayList<>();
List<SubDataObj> subList = new ArrayList<>();
subList.add(new SubDataObj("1"));
GenericEntity<List<DataObj>> entity;
list.add(new DataObj("A", "22", TestEnum.test1, DateTime.now(), subList));
list.add(new DataObj("B", "23", TestEnum.test2, DateTime.now(), subList));
entity = new GenericEntity<List<DataObj>>(list){};
return Response.ok(entity).build();
}
}
Here the service returns the Response fine when not using the subList, which is a object list within the DataObj class. However, when I am using it, i get an error as:
SEVERE: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List<dyno.scheduler.restservice.DataObj>.
Here are the DataObj and the SubDataObj classes:
#XmlRootElement
class DataObj
{
private String name;
private String age;
private TestEnum enumVal;
private DateTime currentDate;
private List<SubDataObj> subData;
public DataObj(String name, String age, TestEnum enumVal, DateTime currentDate, List<SubDataObj> subData)
{
this.name = name;
this.age = age;
this.enumVal = enumVal;
this.currentDate = currentDate;
this.subData = subData;
}
public DataObj() {}
/**
* #return the name
*/
public String getName()
{
return name;
}
/**
* #param name the name to set
*/
public void setName(String name)
{
this.name = name;
}
/**
* #return the age
*/
public String getAge()
{
return age;
}
/**
* #param age the age to set
*/
public void setAge(String age)
{
this.age = age;
}
/**
* #return the enumVal
*/
public TestEnum getEnumVal()
{
return enumVal;
}
/**
* #param enumVal the enumVal to set
*/
public void setEnumVal(TestEnum enumVal)
{
this.enumVal = enumVal;
}
/**
* #return the currentDate
*/
public DateTime getCurrentDate()
{
return currentDate;
}
/**
* #param currentDate the currentDate to set
*/
public void setCurrentDate(DateTime currentDate)
{
this.currentDate = currentDate;
}
/**
* #return the subData
*/
public List<SubDataObj> getSubData()
{
return subData;
}
/**
* #param subData the subData to set
*/
public void setSubData(List<SubDataObj> subData)
{
this.subData = subData;
}
}
DataSubObj class:
class SubDataObj
{
private String subId;
public SubDataObj(String subId)
{
this.subId = subId;
}
/**
* #return the subId
*/
public String getSubId()
{
return subId;
}
/**
* #param subId the subId to set
*/
public void setSubId(String subId)
{
this.subId = subId;
}
}
I tried adding #XmlRootElement annotation to my SubDataObj class as well, which didn't work.
Any help would be appreciated!

Android - Structure of classes for DB Tables + POJO Class can be same?

I have 25+ tables and I have used Content Provider with Database.
I have created separate files for each tables with following structure:
TProductUnit.java in package of com.myapp.db.tables
public class TProductUnit {
/***
* Fields of TABLE_PRODUCT_UNIT Table
***/
public static final String TABLE_PRODUCT_UNIT = "product_unit";
/**
* Columns of TABLE_PRODUCT_UNIT
*/
public static final String PRODUCT_UNIT_SERVER_ID = "id";
public static final String PRODUCT_UNIT_NAME = "name";
public static final String PRODUCT_UNIT_ITP = "itp";
public static final String PRODUCT_UNIT_UTP = "utp";
public static final String PRODUCT_UNIT_STATUS = "status";
public static String[] PRODUCT_UNIT_COLUMNS = new String[] {
BaseColumns._ID,
PRODUCT_UNIT_SERVER_ID,
PRODUCT_UNIT_NAME,
PRODUCT_UNIT_ITP,
PRODUCT_UNIT_UTP,
PRODUCT_UNIT_STATUS
};
}
ProductUnit.java is POJO class which will helpful when First time get data from Server.
public class ProductUnit {
#SerializedName("id")
#Expose
private Integer id;
#SerializedName("product_id")
#Expose
private Integer productId;
#SerializedName("url")
#Expose
private String url;
#SerializedName("bit")
#Expose
private int bit;
#SerializedName("status")
#Expose
private Integer status;
#SerializedName("itp")
#Expose
private String itp;
#SerializedName("utp")
#Expose
private String utp;
/**
* #return The id
*/
public Integer getId() {
return id;
}
/**
* #param id The id
*/
public void setId(Integer id) {
this.id = id;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public int getBit() {
return bit;
}
public void setBit(int bit) {
this.bit = bit;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
/**
* #return The status
*/
public Integer getStatus() {
return status;
}
/**
* #param status The status
*/
public void setStatus(Integer status) {
this.status = status;
}
/**
* #return The itp
*/
public String getItp() {
return itp;
}
/**
* #param itp The itp
*/
public void setItp(String itp) {
this.itp = itp;
}
/**
* #return The utp
*/
public String getUtp() {
return utp;
}
/**
* #param utp The utp
*/
public void setUtp(String utp) {
this.utp = utp;
}
/**
* Convenient method to get the objects data members in ContentValues object.
* This will be useful for Content Provider operations,
* which use ContentValues object to represent the data.
*
* #return
*/
public ContentValues getContentValues() {
ContentValues values = new ContentValues();
values.put(PRODUCT_UNIT_SERVER_ID, id);
values.put(PRODUCT_UNIT_NAME, name);
values.put(PRODUCT_UNIT_ITP, itp);
values.put(PRODUCT_UNIT_UTP, utp);
values.put(PRODUCT_UNIT_STATUS, status);
return values;
}
}
Both classes have most of the same number of fields with same values if we think about #SerializedName
Problem:
Whenever I need to add some fields in any Particular Table then I have to add in all Table file and JSON POJO Class too.
When any field name changed by server side then I have to change in both file.
My Question is: Is there any better solution for this optimization. Have you ever manage like this?
P.S. I have 25+ tables so I have to create 50+ classes.
Help please. Thanks.

Hibernate unable to cast to Java using aggregate functions

I am using Hibernate (and new at it also) and trying to use an aggregate function to retrieve count value and additional fields from a MS SQL database. I have created a POJO class for the data as follows:
package com.hdl.model.db;
import java.util.Date;
#Entity
#Table(name = "sfdc_stg_lab_orders")
#SqlResultSetMappings( {
SqlResultSetMapping(name = "ProfessorAndManager",
columns = { #ColumnResult(name = "total"),
#ColumnResult(name = "org_name"),
#ColumnResult(name = "drawMonth"),
#ColumnResult(name = "drawYear")
})
})
public class OrgnameByMonthYear {
public OrgnameByMonthYear(Id sfdc_stg_lab_order_key, String org_name,int drawMonth,
int drawYear , Double total){
this.org_name = org_name;
this.total = total;
this.drawMonth = drawMonth;
this.drawYear = drawYear;
}
#Id
#GeneratedValue
#Column(name= "sfdc_stg_lab_order_key")
/*
* Unique ID - System Generated
*/
private Integer sfdc_stg_lab_order_key;
/*
* Name of the Organization
*/
#Column(name= "org_name")
private String org_name;
#Column(name = "total")
private double total;
#Column(name = "drawMonth")
private int drawMonth;
#Column(name = "drawYear")
private int drawYear;
public Integer getSfdc_stg_lab_order_key() {
return sfdc_stg_lab_order_key;
}
public void setSfdc_stg_lab_order_key(Integer sfdc_stg_lab_order_key) {
this.sfdc_stg_lab_order_key = sfdc_stg_lab_order_key;
}
/**
* #return the orgname
*/
public String getOrg_name() {
return org_name;
}
/**
* #param orgname to set
*/
public void setOrg_name(String org_name) {
this.org_name = org_name;
}
/**
* #return the year
*/
public double getTotal() {
return total;
}
/**
* #param total to set
*/
public void setTotal(long total) {
this.total = total;
}
/**
* #return the month
*/
public int getDrawMonth() {
return drawMonth;
}
/**
* #param month to set
*/
public void setDrawMonth(int drawMonth) {
this.drawMonth = drawMonth;
}
/**
* #return the year
*/
public int getDrawYear() {
return drawYear;
}
/**
* #param year to set
*/
public void setDrawYear(int drawYear) {
this.drawYear = drawYear;
}
#Override
public String toString() {
return "sfdc_stg_lab_orders [sfdc_stg_lab_order_key=" +
sfdc_stg_lab_order_key + "total=" + total + ", org_name=" + org_name + "]";
}
}
I am calling the following to retrieve the data using Hibernate find:
#SuppressWarnings("unchecked")
#Override
public List<OrgnameByMonthYear> getOrgnameByMonthYear() {
logger.info("Retrieving getOrgnameByMonthYear list inside SfdcStgLabOrdersDAOImpl ....");
return hibernateTemplate.find("select count(org_name) AS total, org_name,
month(specimen_draw_date_1) AS drawMonth, year(specimen_draw_date_1) AS drawYear from
OrgnameByMonthYear group by org_name, month(specimen_draw_date_1),
year(specimen_draw_date_1)");
}
I am getting the following error in Java "Unable to cast to OrgnameByMonthYear class". Thanks in advance for any assistance!
org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'executeFirstTask' on target class [class com.hdl.service.impl.SchedulerService] failed; nested exception is java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.hdl.model.db.OrgnameByMonthYear at
org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:320) at
org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113)
at org.quartz.core.JobRunShell.run(JobRunShell.java:223)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.hdl.model.db.OrgnameByMonthYear
This can be done by creating a new class AggregationResults that contains the results of the query:
public class AggregationResults {
private Integer total;
private String orgName;
private Integer drawMonth;
private Integer drawYear;
... constructor with all properties here ...
}
And then rewrite the query so that it returns AggregationResults using the new operator:
#SuppressWarnings("unchecked")
#Override
public List<AggregationResults> getOrgnameByMonthYear() {
logger.info("Retrieving AggregationResults list inside SfdcStgLabOrdersDAOImpl ....");
return hibernateTemplate.find("select new com.your.package.AggregationResults( count(org_name) AS total, org_name,
month(specimen_draw_date_1) AS drawMonth, year(specimen_draw_date_1) AS drawYear) from
OrgnameByMonthYear group by org_name, month(specimen_draw_date_1),
year(specimen_draw_date_1)");
}

Hibernate error reading data from database

I have created an application using Spring MVC 3, Hibernate and Ext Js 4. The problem is that when I start the application the data is not readed from the database.
BookController.java:
#Controller
public class BookController {
private BookService bookService;
#RequestMapping(value="/books/view.action")
public #ResponseBody Map<String,? extends Object> view(#RequestParam int start, #RequestParam int limit) throws Exception {
try{
List<Book> books = bookService.getBookList(start,limit);
int total = bookService.getTotalBooks();
return ExtJSReturn.mapOK(books, total);
} catch (Exception e) {
return ExtJSReturn.mapError("Error retrieving books from database.");
}
}
BookService.java:
#Service
public class BookService {
private BookDAO bookDAO;
/**
* Get all books
* #return
*/
#Transactional(readOnly=true)
public List<Book> getBookList(int start, int limit){
return bookDAO.getBooks(start, limit);
}
public int getTotalBooks(){
return bookDAO.getTotalBooks();
}
BookDAO.java:
#SuppressWarnings("unchecked")
public List<Book> getBooks(int start, int limit) {
DetachedCriteria criteria = DetachedCriteria.forClass(Book.class);
return hibernateTemplate.findByCriteria(criteria, start, limit);
}
public int getTotalBooks(){
return DataAccessUtils.intResult(hibernateTemplate.find("SELECT COUNT(*) FROM books"));
}
Book.java:
#JsonAutoDetect
#Entity
#Table(name="books")
public class Book {
#Id
#GeneratedValue
#Column(name="id")
private int id;
#Column(name="title", nullable=false)
private String title;
#Column(name="author", nullable=false)
private String author;
#Column(name="publisher", nullable=false)
private String publisher;
#Column(name="isbn", nullable=false)
private String isbn;
#Column(name="pages", nullable=false)
private int pages;
#Column(name="category", nullable=false)
private String category;
#Column(name="qty", nullable=false)
private int qty;
/**
* #return the title
*/
public String getTitle() {
return title;
}
/**
* #param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* #return the author
*/
public String getAuthor() {
return author;
}
/**
* #param author the author to set
*/
public void setAuthor(String author) {
this.author = author;
}
/**
* #return the publisher
*/
public String getPublisher() {
return publisher;
}
/**
* #param publisher the publisher to set
*/
public void setPublisher(String publisher) {
this.publisher = publisher;
}
/**
* #return the isbn
*/
public String getIsbn() {
return isbn;
}
/**
* #param isbn the isbn to set
*/
public void setIsbn(String isbn) {
this.isbn = isbn;
}
/**
* #return the pages
*/
public int getPages() {
return pages;
}
/**
* #param pages the pages to set
*/
public void setPages(int pages) {
this.pages = pages;
}
/**
* #return the category
*/
public String getCategory() {
return category;
}
/**
* #param category the category to set
*/
public void setCategory(String category) {
this.category = category;
}
/**
* #return the qty
*/
public int getQty() {
return qty;
}
/**
* #param qty the qty to set
*/
public void setQty(int qty) {
this.qty = qty;
}
/**
* #return the id
*/
public int getId() {
return id;
}
/**
* #param id the id to set
*/
public void setId(int id) {
this.id = id;
}
}
ExtJsReturn.java:
#Component
public class ExtJSReturn {
/**
* Generates modelMap to return in the modelAndView
* #param books
* #return
*/
public static Map<String,Object> mapOK(List<Book> books){
Map<String,Object> modelMap = new HashMap<String,Object>(3);
modelMap.put("total", books.size());
modelMap.put("data", books);
modelMap.put("success", true);
return modelMap;
}
/**
* Generates modelMap to return in the modelAndView
* #param books
* #return
*/
public static Map<String,Object> mapOK(List<Book> books, int total){
Map<String,Object> modelMap = new HashMap<String,Object>(3);
modelMap.put("total", total);
modelMap.put("data", books);
modelMap.put("success", true);
return modelMap;
}
/**
* Generates modelMap to return in the modelAndView in case
* of exception
* #param msg message
* #return
*/
public static Map<String,Object> mapError(String msg){
Map<String,Object> modelMap = new HashMap<String,Object>(2);
modelMap.put("message", msg);
modelMap.put("success", false);
return modelMap;
}
}
The error is raised from the controller: Error retrieving books from database.
Do you have any ideea what can be the problem?
See here the Console output: http://pastebin.com/jMQKS31P
FIXED!!!
https://stackoverflow.com/a/14447201/1564840
You're passing a SQL request, using tables and column names, to a method which expects an HQL request, using entities, mapped fields and associations. SQL and HQL are two different query languages.
The HQL query should be
select count(book.id) from Book book
If you don't know about HQL, then you really need to read the documentation. Using Hibernate without knowing HQL is like using JDBC without knowing SQL.

How to assign JSON Object to Hibernate Pojo + ext js 4 + Java + spring

I am using JPA, Spring, Ext js 4 mvc and mysql5.0 server
One problem i am facing is that i am not able to insert my data to database using Hibernate + JPA.
I am sending the data to server side using JSON and then this object interact with database and insert the json object to the database.
I am sending the json data as
"Id": null,
"Name": "New task",
"StartDate": "2010-02-13T05:30:00",
"EndDate": "2010-02-13T05:30:00",
"Duration": 0,
"DurationUnit": "d",
"PercentDone": 0,
"ManuallyScheduled": false,
"Priority": 1,
"parentId": 22,
"index": 2,
"depth": 2,
"checked": null
my Hibernate POJO is
private int id;
private Date startDate;
private Date endDate;
private int percentDone;
private String name;
private int priority;
private double duration;
private String durationUnit;
private int index;
private int depth;
private int parentId;
/**
* #return the id
*/
#Id
#GeneratedValue
#Column(name = "TASK_Id")
public int getId() {
return id;
}
/**
* #param id the id to set
*/
public void setId(int Id) {
this.id = Id;
}
/**
* #return the startDate
*/
#Temporal(TemporalType.DATE)
#Column(name = "TASK_Start_Date")
public Date getStartDate() {
return startDate;
}
/**
* #param startDate the startDate to set
*/
public void setStartDate(Date StartDate) {
this.startDate = StartDate;
}
/**
* #return the endDate
*/
#Temporal(TemporalType.DATE)
#Column(name = "TASK_End_Date")
public Date getEndDate() {
return endDate;
}
/**
* #param endDate the endDate to set
*/
public void setEndDate(Date EndDate) {
this.endDate = EndDate;
}
/**
* #return the percentDone
*/
#Column(name = "TASK_Percent_Done")
public int getPercentDone() {
return percentDone;
}
/**
* #param percentDone the percentDone to set
*/
public void setPercentDone(int PercentDone) {
this.percentDone = PercentDone;
}
/**
* #return the name
*/
#Column(name = "TASK_Name")
public String getName() {
return name;
}
/**
* #param name the name to set
*/
public void setName(String Name) {
this.name = Name;
}
/**
* #return the priority
*/
#Column(name = "TASK_Priority")
public int getPriority() {
return priority;
}
/**
* #param priority the priority to set
*/
public void setPriority(int Priority) {
this.priority = Priority;
}
/**
* #return the duration
*/
#Column(name = "TASK_Duration")
public double getDuration() {
return duration;
}
/**
* #param duration the duration to set
*/
public void setDuration(double Duration) {
this.duration = Duration;
}
/**
* #return the durationUnit
*/
#Column(name = "TASK_DurationUnit")
public String getDurationUnit() {
return durationUnit;
}
/**
* #param durationUnit the durationUnit to set
*/
public void setDurationUnit(String DurationUnit) {
this.durationUnit = DurationUnit;
}
/**
* #return the index
*/
#Column(name = "TASK_Index")
public int getIndex() {
return index;
}
/**
* #param index the index to set
*/
public void setIndex(int index) {
this.index = index;
}
/**
* #return the depth
*/
#Column(name = "TASK_Depth")
public int getDepth() {
return depth;
}
/**
* #param depth the depth to set
*/
public void setDepth(int depth) {
this.depth = depth;
}
/**
* #return the parentId
*/
#Column(name = "TASK_ParentId")
public int getParentId() {
return parentId;
}
/**
* #param parentId the parentId to set
*/
public void setParentId(int parentId) {
this.parentId = parentId;
}
when i am passing the above JSON data nothing get inserted to my database.
my hibernate query fires like
`Hibernate: insert into TASK(TASK_Depth, TASK_Duration, TASK_DurationUnit, TASK_End_Date, TASK_Index, TASK_Name, TASK_ParentId, TASK_Percent_Done, TASK_Priority, TASK_Start_Date)
values( ? , ?, ?, ?, ?, ?, ?, ?, ?, ?)`
nothing get inserted to my database. As my class id is autoincreemented the record gets created with empty name, startDate, endDate, parentId
So my question is that what the things i am doing wrong. Is there any problem with my hibernate Pojo mappings . If yes then any one having solution to this problem may reply to my thread.
I would suggest you to divide your issue into several areas.
Have you tried to create a POJO manually (without conversion from JSON) and store it in your DB?
If it works, your mappings are OK, if not - the POJO is not relevant here, fix your JPA mappings.
Assuming it worked, the issue must be converting your JSON (after all, somewhere on server it converts json (string) to Java Object and creates your POJO), maybe it fails to convert dates, or your framework is not set up properly. One way or another this should be
easily revealed by your favorite debugger :)
I remember I've used a Direct Web Remoting (DWR) project to send data from ExtJS to the Java based server (the data was sent in a JSON format) so I can't really elaborate on your conversion method.
Hope this helps

Categories

Resources