How to use Oracle sequence with Hibernate + Spring - spring

Inside my entity class
package com.entity;
// Generated May 23, 2015 10:43:49 PM by Hibernate Tools 4.3.1
import java.math.BigDecimal;
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.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* EmpTest generated by hbm2java
*/
#Entity
#Table(name="EMP_TEST"
,schema="SCOTT"
)
public class EmpTest implements java.io.Serializable {
private BigDecimal id;
private String ename;
private Date dob;
private BigDecimal sal;
public EmpTest() {
}
public EmpTest(BigDecimal id, String ename, Date dob, BigDecimal sal) {
this.id = id;
this.ename = ename;
this.dob = dob;
this.sal = sal;
}
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "test_seq")
#SequenceGenerator(name = "test_seq",
sequenceName = "TEST_SEQ" , allocationSize=1)
#Column(name="ID", unique=true, nullable=false, precision=22, scale=0)
public BigDecimal getId() {
return this.id;
}
public void setId(BigDecimal id) {
this.id = id;
}
#Column(name="ENAME", nullable=false, length=50)
public String getEname() {
return this.ename;
}
public void setEname(String ename) {
this.ename = ename;
}
#Temporal(TemporalType.DATE)
#Column(name="DOB", nullable=false, length=7)
public Date getDob() {
return this.dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
#Column(name="SAL", nullable=false, precision=5)
public BigDecimal getSal() {
return this.sal;
}
public void setSal(BigDecimal sal) {
this.sal = sal;
}
}
TEST_SEQ is the sequence, which I created under my schema. But, when I'm trying to add record then getting following exception
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: select this_.ID as ID1_0_0_, this_.ENAME as ENAME2_0_0_, this_.DOB as DOB3_0_0_, this_.SAL as SAL4_0_0_ from SCOTT.EMP_TEST this_
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:89)
at org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:122)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:115)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:711)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:703)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:698)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:356)
at com.sun.proxy.$Proxy318.save(Unknown Source)
at com.model.EmpModelImp.add(EmpModelImp.java:32)
at com.model.EmpServiceImpl.add(EmpServiceImpl.java:27)
at com.controller.EmpControl.doActions(EmpControl.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1034)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:791)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:866)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1186)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3387)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3431)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
... 62 more
I have noticed that, It is trying to get next value from hibernate_sequence sequence, which doesn't exist in my database. On the other hand in my entity class I have pointed to TEST_SEQ, which exist in my database. I don't why It trying to get next sequence value from hibernate_sequence. Anyone please help me on this ?
==Update==
EmpTest.hbm.xml
<hibernate-mapping>
<class name="com.entity.EmpTest" table="EMP_TEST" schema="SCOTT" optimistic-lock="version">
<id name="id" type="big_decimal">
<column name="ID" precision="22" scale="0" />
<generator class="sequence" />
</id>
<property name="ename" type="string">
<column name="ENAME" length="50" not-null="true" />
</property>
<property name="dob" type="date">
<column name="DOB" length="7" not-null="true" />
</property>
<property name="sal" type="big_decimal">
<column name="SAL" precision="5" not-null="true" />
</property>
</class>
</hibernate-mapping>
Add function insert record into table
public void add(EmpTest emp) {
try {
session = HibernateUtil.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();
System.out.println(emp.getEname()+" "+emp.getDob());
session.save(emp);
tx.commit();
} catch (Exception ex) {
tx.rollback();
ex.printStackTrace();
}
}

Your EmpTest.hbm.xml mapping file does not reference your sequence. Try changing it to the following:
<hibernate-mapping>
<class name="com.entity.EmpTest" table="EMP_TEST" schema="SCOTT" optimistic-lock="version">
<id name="id" type="big_decimal">
<column name="ID" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">TEST_SEQ</param>
</generator>
</id>
<property name="ename" type="string">
<column name="ENAME" length="50" not-null="true" />
</property>
<property name="dob" type="date">
<column name="DOB" length="7" not-null="true" />
</property>
<property name="sal" type="big_decimal">
<column name="SAL" precision="5" not-null="true" />
</property>
</class>
</hibernate-mapping>

Related

Unkown column in 'field list' after creating tables by liquibase

I prepare liquibase scripts to generate my tables and relationships.
ChangeLog which create relationships:
<changeSet id="1" author="xyz">
<createTable tableName="drivers_and_tickets">
<column name="driver_id" type="varchar(36)">
<constraints nullable="false" />
</column>
<column name="ticket_id" type="varchar(36)">
<constraints nullable="false" />
</column>
</createTable>
<addForeignKeyConstraint constraintName="fk_drivers"
baseTableName="drivers_and_tickets" baseColumnNames="driver_id"
referencedTableName="drivers" referencedColumnNames="id" />
<addForeignKeyConstraint constraintName="fk_tickets"
baseTableName="drivers_and_tickets" baseColumnNames="ticket_id"
referencedTableName="tickets" referencedColumnNames="id" />
</changeSet>
<changeSet id="2" author="xyz">
<createTable tableName="tickets_and_offences">
<column name="ticket_id" type="varchar(36)">
<constraints nullable="false" />
</column>
<column name="offence_id" type="varchar(36)">
<constraints nullable="false" />
</column>
</createTable>
<addForeignKeyConstraint constraintName="fk_tickets_from_offences"
baseTableName="tickets_and_offences" baseColumnNames="ticket_id"
referencedTableName="tickets" referencedColumnNames="id" />
<addForeignKeyConstraint constraintName="fk_offences"
baseTableName="tickets_and_offences" baseColumnNames="offence_id"
referencedTableName="offences" referencedColumnNames="id" />
</changeSet>
And it ok, app is starting without any errors.
I use hibernate too, so I prepared entites:
public class DriverEntity {
#Id
#GeneratedValue(generator = "system-uuid")
#GenericGenerator(name = "system-uuid", strategy = "uuid")
private String id;
private String name;
private String surname;
private String email;
#OneToMany(mappedBy="driver")
private List<TicketEntity> tickets;
public class TicketEntity {
#Id
#GeneratedValue(generator = "system-uuid")
#GenericGenerator(name = "system-uuid", strategy = "uuid")
private String id;
private LocalDate date;
#OneToMany(mappedBy="ticket")
private Set<OffenceEntity> offences;
#ManyToOne
#JoinColumn(name="driver_id")
private DriverEntity driver;
and next when I call repository findAllDrivers I am getting error:
"Unknown column 'tickets0_.driver_id' in 'field list'" .
When I was using hibernate.ddl-auto mapping like that in entities was enough to create tables and getting records from database.
Edit:
I have checked how it looks in my DB and do not know what is wrong

Link subreport connected to database with mainreport that is sent by controller it won't work even with adding parameter?

I have 3 entities orderclient and orderlineclient: relation one-to-many
and orderlineclient and product: relation many-to-many. I send orderlines to jasper file with this method:
#GetMapping("/pdf/{id}")
public ModelAndView report(#PathVariable("id") Long id) throws JRException {
JasperReportsPdfView view = new JasperReportsPdfView();
view.setUrl("classpath:clientreport.jrxml");
view.setApplicationContext(appContext);
Map<String, Object> params = new HashMap<>();
Client client = clientRepository.findOne(id);
List<OrderClient> ordersClient = orderClientRepository.findByClient(client);
List<OrderLineClient> orderLines = new ArrayList<>();
for (OrderClient order : ordersClient) {
orderLines.addAll(order.getOrderLineClients());
}
params.put("source", orderLines);
return new ModelAndView(view, params);
}
Then I create a sub-report and I link it directly to the database. After, I create a param and run the following SQL:
SELECT product.id,
product.name,
product.price,
order_line_client.id,
order_line_client.price,
order_line_client.quantities,
order_line_client.tooths
FROM product,
order_line_products,
order_line_client
WHERE
product.id = order_line_products.product_id
AND order_line_products.order_line_id = order_line_client.id
AND order_line_client.order_client_id = $P{orderid}
But when I run the app I get exceptions. Can someone please help me get the following:
date of order
number of order
product
quantities
price
totalPrice
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
#Entity
public class OrderClient {
// Attributes
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String number;
private Date orderDate;
private String notes;
private String patientName;
#ManyToOne
private Client client;
#OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy = "orderClient")
private List<OrderLineClient> orderLineClients = new ArrayList<>();
// Getters & Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public Date getOrderDate() {
return orderDate;
}
public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public String getPatientName() {
return patientName;
}
public void setPatientName(String patientName) {
this.patientName = patientName;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public List<OrderLineClient> getOrderLineClients() {
return orderLineClients;
}
public void setOrderLineClients(List<OrderLineClient> orderLineClients) {
this.orderLineClients = orderLineClients;
}
/**
* equals method
*
* #param o
* #return
*/
#Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
OrderClient order = (OrderClient) o;
return Objects.equals(id, order.id);
}
/**
* hashCode method
*
* #return
*/
#Override
public int hashCode() {
return Objects.hash(id);
}
}
order line client
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
#Entity
public class OrderLineClient {
#Id
#GeneratedValue
private Long id;
private String quantities;
private Double price;
private String tooths;
#ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
#JoinTable(name="orderLine_products", joinColumns=#JoinColumn(name="orderLine_id"), inverseJoinColumns=#JoinColumn(name="product_id"))
private List<Product> products = new ArrayList<>();
#ManyToOne
private Category category;
#ManyToOne
private OrderClient orderClient;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public String getQuantities() {
return quantities;
}
public void setQuantities(String quantities) {
this.quantities = quantities;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getTooths() {
return tooths;
}
public void setTooths(String tooths) {
this.tooths = tooths;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
public OrderClient getOrderClient() {
return orderClient;
}
public void setOrderClient(OrderClient orderClient) {
this.orderClient = orderClient;
}
public List<Double> getQuantitiesValues(){
if (getQuantities() == null ) return null;
if (getQuantities().contains("/"))
return CollectionUtils.convertList( Arrays.asList(getQuantities().split("/")), s -> Double.parseDouble(s) );
else {
return Collections.singletonList(Double.parseDouble(getQuantities()));
}
}
public List<String> getToothsValues(){
if (getTooths() == null) return null;
if (getTooths().contains("/"))
return Arrays.asList(getTooths().split("/"));
else
return Collections.singletonList(getTooths());
}
#Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
OrderLineClient that = (OrderLineClient) o;
return Objects.equals(id, that.id);
}
#Override
public int hashCode() {
return Objects.hash(id);
}
}
product
import javax.persistence.CascadeType;
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.JoinTable;
import javax.persistence.ManyToMany;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
#Entity
public class Product {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Column(nullable = false)
private String name;
private Double price;
private String unit;
private Double quantity;
private Double quantityMin;
private Double quantityMax;
private String picture;
#ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy = "products")
private List<OrderLineClient> orderLineClients = new ArrayList<>();
#ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
#JoinTable(name="product_category", joinColumns=#JoinColumn(name="product_id"), inverseJoinColumns=#JoinColumn(name="category_id"))
private List<Category> categories = new ArrayList<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Double getQuantity() {
return quantity;
}
public void setQuantity(Double quantity) {
this.quantity = quantity;
}
public Double getQuantityMin() {
return quantityMin;
}
public void setQuantityMin(Double quantityMin) {
this.quantityMin = quantityMin;
}
public Double getQuantityMax() {
return quantityMax;
}
public void setQuantityMax(Double quantityMax) {
this.quantityMax = quantityMax;
}
public String getPicture() {
return picture;
}
public void setPicture(String picture) {
this.picture = picture;
}
public List<OrderLineClient> getOrderLineClients() {
return orderLineClients;
}
public void setOrderLineClients(List<OrderLineClient> orderLineClients) {
this.orderLineClients = orderLineClients;
}
public List<Category> getCategories() {
return categories;
}
public void setCategories(List<Category> categories) {
this.categories = categories;
}
public Category getParentCategory(){
return getCategories().isEmpty() ? null : getCategories().get(0).getParentCategory();
}
public boolean isOneCategory(Category category ){
return categories.stream().anyMatch(category::equals);
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Product product = (Product) o;
return Objects.equals(id, product.id);
}
#Override
public int hashCode() {
return Objects.hash(id);
}
}
this is the exception
net.sf.jasperreports.engine.JRException: Resource not found at: src/main/resources/underreport.jasper.
at net.sf.jasperreports.repo.RepositoryUtil.getResourceFromLocation(RepositoryUtil.java:153) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.repo.RepositoryUtil.getReport(RepositoryUtil.java:112) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRFillSubreport.loadReport(JRFillSubreport.java:402) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:369) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:431) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:345) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:383) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:533) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2549) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:791) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:252) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:99) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:609) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:405) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:140) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:667) ~[jasperreports-6.5.1.jar:6.5.1]
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:983) ~[jasperreports-6.5.1.jar:6.5.1]
at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.fillReport(AbstractJasperReportsView.java:681) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.renderMergedOutputModel(AbstractJasperReportsView.java:566) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110) ~[spring-boot-actuator-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
this is the main report
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.0.final using JasperReports Library version 6.5.0 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="clientreport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f5644a3e-c1ef-42f5-b449-e1d38e2d0fd8">
<queryString>
<![CDATA[]]>
</queryString>
<field name="orderClient.id" class="java.lang.Long"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="227" y="24" width="100" height="30" uuid="e75f9094-468e-4cf0-83ad-ed751fddd3fd"/>
<textElement textAlignment="Center">
<font size="18" isBold="true"/>
</textElement>
<text><![CDATA[Facture]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="241" splitType="Stretch">
<line>
<reportElement x="-40" y="10" width="615" height="1" uuid="97823373-89aa-42e5-b490-093c4c733c8d"/>
</line>
<line>
<reportElement x="-40" y="61" width="615" height="1" uuid="0db72487-cd75-44f9-adfa-960ba7228c69"/>
</line>
<line>
<reportElement x="71" y="10" width="1" height="51" uuid="361295c4-4882-4557-a9fb-7ebc9cb2f85e"/>
</line>
<line>
<reportElement x="167" y="10" width="1" height="51" uuid="d955e6d9-f764-4beb-9dd3-9894d1c63e1b"/>
</line>
<line>
<reportElement x="280" y="11" width="1" height="50" uuid="a3695a4f-8c97-416c-8eaf-0969e89928dd"/>
</line>
<staticText>
<reportElement x="-20" y="20" width="100" height="30" uuid="fb2c51d1-f35f-4c81-8cb6-26bdfc788bbe">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="a0b6a2a6-515d-45cd-a542-2dc271b1b56f"/>
</reportElement>
<text><![CDATA[orderClient.id]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="233" splitType="Stretch">
<textField>
<reportElement x="-20" y="0" width="100" height="30" uuid="cacba138-4c84-4a2d-9f82-dd47a2685203">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="a0b6a2a6-515d-45cd-a542-2dc271b1b56f"/>
</reportElement>
<textFieldExpression><![CDATA[$F{orderClient.id}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="250" y="30" width="200" height="151" uuid="3a4a68df-12fa-4e4b-a3d5-8ba43f819e1d"/>
<subreportParameter name="orderid">
<subreportParameterExpression><![CDATA[$F{orderClient.id}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["src/main/resources/underreport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
this is the subreport
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.0.final using JasperReports Library version 6.5.0 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="underreport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3365f770-336c-4f9c-a25f-0886872566e0">
<property name="com.jaspersoft.studio.data.sql.tables">
<![CDATA[cHJvZHVjdCAsMTM5LDI4LDc0MGI5ZWIxLTY4OGYtNGI3MS1hOGVjLWY3NDA0ZWE2ZmIzOTtvcmRl
cl9saW5lX3Byb2R1Y3RzICwyMzUsNDEsZWY1N2VmY2EtZDNmYS00MTNhLWE0MTgtNzA5ODU2ZWEz
YTQ0O29yZGVyX2xpbmVfY2xpZW50ICwxNSwxNSxmOTdiYTY2OC03MTNiLTQzNzAtYWI0MS1kODFi
YmM4MGFiZTE7]]>
</property>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JDBC Data Adapter"/>
<parameter name="orderid" class="java.lang.Long"/>
<queryString language="SQL">
<![CDATA[SELECT product.id,
product.name,
product.price,
order_line_client.id,
order_line_client.price,
order_line_client.quantities,
order_line_client.tooths
FROM product,
order_line_products,
order_line_client
WHERE
product.id = order_line_products.product_id
AND order_line_products.order_line_id = order_line_client.id]]>
</queryString>
<field name="id" class="java.lang.Long">
<property name="com.jaspersoft.studio.field.label" value="id"/>
<property name="com.jaspersoft.studio.field.tree.path" value="product"/>
</field>
<field name="name" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="name"/>
<property name="com.jaspersoft.studio.field.tree.path" value="product"/>
</field>
<field name="price" class="java.lang.Double">
<property name="com.jaspersoft.studio.field.label" value="price"/>
<property name="com.jaspersoft.studio.field.tree.path" value="product"/>
</field>
<field name="COLUMN_4" class="java.lang.Long">
<property name="com.jaspersoft.studio.field.label" value="id"/>
<property name="com.jaspersoft.studio.field.tree.path" value="order_line_client"/>
</field>
<field name="COLUMN_5" class="java.lang.Double">
<property name="com.jaspersoft.studio.field.label" value="price"/>
<property name="com.jaspersoft.studio.field.tree.path" value="order_line_client"/>
</field>
<field name="quantities" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="quantities"/>
<property name="com.jaspersoft.studio.field.tree.path" value="order_line_client"/>
</field>
<field name="tooths" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="tooths"/>
<property name="com.jaspersoft.studio.field.tree.path" value="order_line_client"/>
</field>
<group name="id">
<groupExpression><![CDATA[$F{id}]]></groupExpression>
</group>
<group name="name">
<groupExpression><![CDATA[$F{name}]]></groupExpression>
</group>
<group name="price">
<groupExpression><![CDATA[$F{price}]]></groupExpression>
</group>
<group name="COLUMN_4">
<groupExpression><![CDATA[$F{COLUMN_4}]]></groupExpression>
</group>
<group name="COLUMN_5">
<groupExpression><![CDATA[$F{COLUMN_5}]]></groupExpression>
</group>
<group name="quantities">
<groupExpression><![CDATA[$F{quantities}]]></groupExpression>
</group>
<group name="tooths">
<groupExpression><![CDATA[$F{tooths}]]></groupExpression>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="4d24ee13-0586-4ab5-8804-0f984acdd187">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="0e5824f5-b3da-4bba-88b6-b57f5fb9d886"/>
</reportElement>
<text><![CDATA[name]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="616ff217-cfb2-496c-bbb8-0f4ee2a644b8">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="0e5824f5-b3da-4bba-88b6-b57f5fb9d886"/>
</reportElement>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>

Hibernate Mapping - Converting XML to Annotation - Wrong Column name being generated

I have a two projects in hibernate one is for XML and one is for annotation.
My XML Mapping config works fine with composite keys while the annotation style generates a wrong column.
Annotation Style Generates this table
Hibernate: create table agent (agent_id number(10,0) not null, start_dttm timestamp not null, agent_cd varchar2(255 char), end_dttm timestamp, primary key (agent_id, start_dttm))
Hibernate: create table agent_license (agent_license_id number(10,0) not null, agent_agent_id number(10,0), agent_start_dttm timestamp, agent_id number(10,0), primary key (agent_license_id))
Hibernate: alter table agent_license add constraint FKncan0jjmt1siq0a6a19ll978m foreign key (agent_agent_id, agent_start_dttm) references agent
Hibernate: alter table agent_license add constraint FKp64d6078jnxi3hq0n0es0yhs foreign key (agent_id, agent_start_dttm) references agent
a redundant column for AgentLicense with agent_agent_id instead of agent_id only.
This is Working Correctly XML Config
XML generates
Agent Table with column agent_id,start_dttm,agent_cd
Agent_License with column agent_id,agent_start_dttm
Agent Model
<class name="com.poc.model.Agent" table="AGENT">
<composite-id name="id" class="com.poc.model.pk.AgentPK">
<key-property name="agentId" type="long">
<column name="AGENT_ID" precision="10" scale="0" />
</key-property>
<key-property name="startDateTime" type="timestamp">
<column name="START_DTTM" />
</key-property>
</composite-id>
<property name="agentCode" type="string">
<column name="AGENT_CD" length="20" />
</property>
<set name="agentLicenses" table="AGENT_LICENSE" inverse="true" lazy="true" fetch="select">
<key>
<column name="AGENT_ID" precision="10" scale="0" />
<column name="AGENT_START_DTTM" />
</key>
<one-to-many class="com.poc.model.AgentLicense" />
</set>
</class>
AgentLicense Model
<class name="com.poc.model.AgentLicense" table="AGENT_LICENSE">
<id name="agentLicenseId" type="long">
<column name="AGENT_LICENSE_ID" precision="10" scale="0" />
<generator class="assigned" />
</id>
<many-to-one name="agent" class="com.poc.model.Agent" fetch="select">
<column name="AGENT_ID" precision="10" scale="0" />
<column name="AGENT_START_DTTM" />
</many-to-one>
<property name="licenseNum" type="string">
<column name="LICENSE_NUM" length="40" />
</property>
</class>
Agent PK Model
<class name="com.poc.model.Agent" table="AGENT">
<composite-id name="id" class="com.poc.model.pk.AgentPK">
<key-property name="agentId" type="long">
<column name="AGENT_ID" precision="10" scale="0" />
</key-property>
<key-property name="startDateTime" type="timestamp">
<column name="START_DTTM" />
</key-property>
</composite-id>
<property name="agentCode" type="string">
<column name="AGENT_CD" length="20" />
</property>
<set name="agentLicenses" table="AGENT_LICENSE" inverse="true" lazy="true" fetch="select">
<key>
<column name="AGENT_ID" precision="10" scale="0" />
<column name="AGENT_START_DTTM" />
</key>
<one-to-many class="com.poc.model.AgentLicense" />
</set>
</class>
Correct Annotation is this
Result table generation
Agent Table with column agent_id,start_dttm,agent_cd
Agent_License with column agent_id,agent_start_dttm
public class Agent {
#EmbeddedId
#AttributeOverrides({
#AttributeOverride(name = "agentId", column = #Column(name = "AGENT_ID", nullable = false)),
#AttributeOverride(name = "startDateTime", column = #Column(name = "START_DTTM", nullable = false)) })
private AgentPK agentPK;
#Column(name="AGENT_CODE")
private String agentCode;
#OneToMany(fetch = FetchType.LAZY, mappedBy = "agent")
private Set<AgentLicense> agentLicenses = new HashSet<AgentLicense>();
}
public class AgentLicense {
#Id
#Column(name = "AGENT_LICENSE_ID", unique = true, nullable = false)
private long agentLicenseId;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumns({ #JoinColumn(name = "AGENT_ID", referencedColumnName = "AGENT_ID"),
#JoinColumn(name = "AGENT_START_DTTM", referencedColumnName = "START_DTTM") })
private Agent agent;
}
#Embeddable
public class AgentPK implements Serializable{
#Column(name = "AGENT_ID", nullable = false, precision = 10, scale = 0)
private long agentId;
#Column(name = "START_DTTM", nullable = false)
#Temporal(TemporalType.TIMESTAMP)
private Date startDateTime;
//HashCode and equals here
}
Correct Full answer
Fix your inverse mapping for AgentLicense in Agent
public class Agent {
// ...
#OneToMany(mappedBy = "agent")
#JoinColumns( ... )
private Set<AgentLicense> agentLicenses;
}

GlassFish 4.1.1 Spring 4.0.9, EclipseLink, PostgreSQL - transaction marked for rollback with no information

I want to set up an application running on GlassFish 4.1.1 with EclipseLink and Spring. My database is PostgreSQL. Below is my configuration. When I try to invoke /facebookDebug method I get "javax.transaction.RollbackException: Transaction marked for rollback" which is not very descriptive. Please look at my configuration. Is there everything ok? I can add a log from the server start, maybe you will find something there.
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="amleto-server-model" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>amleto-server-model</jta-data-source>
<class>com.amleto.server.model.entities.FacebookDebug</class>
<properties>
<property name="eclipselink.logging.level" value="ALL" />
<property name="eclipselink.logging.level.sql" value="ALL"/>
<property name="eclipselink.logging.parameters" value="true" />
<property name="eclipselink.logging.connection" value="true" />
<property name="eclipselink.logging.session" value="true" />
<property name="eclipselink.logging.thread" value="true" />
<property name="eclipselink.logging.timestamp" value="true" />
<property name="eclipselink.target-database" value="PostgreSQL" />
</properties>
</persistence-unit>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<context:property-placeholder location="classpath:config.properties" ignore-unresolvable="true" />
<context:annotation-config />
<!-- controllers -->
<mvc:annotation-driven />
<context:component-scan base-package="com.amleto.server.model.entities" />
<context:component-scan base-package="com.amleto.server.services.controllers" />
<jpa:repositories base-package="com.amleto.server.model.repositories"/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="amleto-server-model"/>
</bean>
<tx:jta-transaction-manager />
<tx:annotation-driven/>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
</beans>
FacebookDebug.java
package com.amleto.server.model.entities;
import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
#Entity
#Table(name="facebook_debug")
#NamedQuery(name="FacebookDebug.findAll", query="SELECT f FROM FacebookDebug f")
public class FacebookDebug implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="facebook_debug_id")
private Integer facebookDebugId;
#Column(name="app_action")
private String appAction;
#Column(name="date_create")
private Timestamp dateCreate;
#Column(name="user_id")
private String userId;
public FacebookDebug() {
}
public Integer getFacebookDebugId() {
return this.facebookDebugId;
}
public void setFacebookDebugId(Integer facebookDebugId) {
this.facebookDebugId = facebookDebugId;
}
public String getAppAction() {
return this.appAction;
}
public void setAppAction(String appAction) {
this.appAction = appAction;
}
public Timestamp getDateCreate() {
return this.dateCreate;
}
public void setDateCreate(Timestamp dateCreate) {
this.dateCreate = dateCreate;
}
public String getUserId() {
return this.userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
}
FacebookDebugRepository.java
package com.amleto.server.model.repositories;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.amleto.server.model.entities.FacebookDebug;
#Repository
public interface FacebookDebugRepository extends CrudRepository<FacebookDebug, Integer> {
}
AmletoController.java
package com.amleto.server.services.controllers;
import java.sql.Timestamp;
import java.util.GregorianCalendar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.amleto.server.model.entities.FacebookDebug;
import com.amleto.server.model.repositories.FacebookDebugRepository;
#Controller
public class AmletoController {
#Autowired
FacebookDebugRepository repo;
#Transactional
#ResponseBody
#RequestMapping(value = "/facebookDebug", method=RequestMethod.GET)
public String facebookDebug(#RequestParam(value="action", required=true) String action,
#RequestParam(value="userId", required=true) String userId) {
String returnValue = "";
FacebookDebug fb = new FacebookDebug();
fb.setAppAction(action);
fb.setUserId(userId);
GregorianCalendar dateCreate = new GregorianCalendar();
fb.setDateCreate(new Timestamp(dateCreate.getTimeInMillis()));
repo.save(fb);
return "Grazie.";
}
}
stacktrace:
[2015-11-08T17:33:46.604+0100] [glassfish 4.1] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=29 _ThreadName=http-listener-1(4)] [timeMillis: 1447000426604] [levelValue: 900] [[
StandardWrapperValve[spring-dispatcher]: Servlet.service() for servlet spring-dispatcher threw exception
javax.transaction.RollbackException: Transaction marked for rollback.
at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:445)
at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:854)
at com.sun.enterprise.transaction.UserTransactionImpl.commit(UserTransactionImpl.java:212)
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1021)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:485)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy229.save(Unknown Source)
at com.amleto.server.services.controllers.amletoController.facebookDebug(amletoController.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:722)
]]
I have found a solution (which leads me to another error, but it is a step forward).
It turned out that I had to change target-database value to "Database". There is a known EclipseLink bug which throws an exception unless the value of the parameter is equal to "Database". Now I have another problem which can be found here.

No JQPL entity name - database table name mismatch, but it also says The abstract schema type 'Movie' is unknown

I want to build a simple web application using Spring, Eclipselink and MySQL, running on Wildfly 8.2. I want to run a simple query, but I'm keep getting this error:
13:47:37,144 ERROR [io.undertow.request] (default task-9) UT005023: Exception handling request to /MovieTimeProject/hello: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [SELECT m FROM Movie m WHERE m.title LIKE 'Eternal sunshine of%'].
[14, 19] The abstract schema type 'Movie' is unknown.
[28, 35] The state field path 'm.title' cannot be resolved to a valid type.
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_31]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_31]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_31]
Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [SELECT m FROM Movie m WHERE m.title LIKE 'Eternal sunshine of%'].
[14, 19] The abstract schema type 'Movie' is unknown.
[28, 35] The state field path 'm.title' cannot be resolved to a valid type.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1616) [eclipselink.jar:2.6.0.v20150309-bf26070]
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1636) [eclipselink.jar:2.6.0.v20150309-bf26070]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_31]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_31]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_31]
at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_31]
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:291) [spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at com.sun.proxy.$Proxy60.createQuery(Unknown Source)
at com.movietime.repositories.MovieRepository.findMoviesByTitle(MovieRepository.java:34) [classes:]
at com.movietime.dataservices.DataService.findMoviesByTitle(DataService.java:27) [classes:]
at com.movietime.dataservices.DataService$$FastClassBySpringCGLIB$$52da0303.invoke(<generated>) [spring-core-4.1.6.RELEASE.jar:]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717) [spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) [spring-tx-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) [spring-tx-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) [spring-tx-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653) [spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at com.movietime.dataservices.DataService$$EnhancerBySpringCGLIB$$283ef398.findMoviesByTitle(<generated>) [spring-core-4.1.6.RELEASE.jar:]
at com.movietime.controller.HelloController.welcomePage(HelloController.java:29) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_31]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_31]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_31]
at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_31]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
... 30 more
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [SELECT m FROM Movie m WHERE m.title LIKE 'Eternal sunshine of%'].
[14, 19] The abstract schema type 'Movie' is unknown.
[28, 35] The state field path 'm.title' cannot be resolved to a valid type.
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:155) [eclipselink.jar:2.6.0.v20150309-bf26070]
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:347) [eclipselink.jar:2.6.0.v20150309-bf26070]
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:278) [eclipselink.jar:2.6.0.v20150309-bf26070]
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:163) [eclipselink.jar:2.6.0.v20150309-bf26070]
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:142) [eclipselink.jar:2.6.0.v20150309-bf26070]
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:116) [eclipselink.jar:2.6.0.v20150309-bf26070]
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:102) [eclipselink.jar:2.6.0.v20150309-bf26070]
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:86) [eclipselink.jar:2.6.0.v20150309-bf26070]
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1614) [eclipselink.jar:2.6.0.v20150309-bf26070]
... 63 more
I Googled a lot, and people are getting this error if they are not using JPQL correctly, however I am.
Here is my project structure.
Columns of the movies table.
The exception is thrown here, in the MovieRepository class:
package com.movietime.repositories;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.movietime.entities.Actor;
import com.movietime.entities.Movie;
#Repository
#Scope(value="singleton")
public class MovieRepository {
#PersistenceContext
private EntityManager em;
//#Transactional
public void register(Movie mov) {
// Save employee
this.em.persist(mov);
}
#SuppressWarnings("unchecked")
public List<Movie> findMoviesByTitle(String title) {
String queryString = "SELECT m FROM Movie m WHERE m.title LIKE '" + title + "%'";
Query query = em.createQuery(queryString, Movie.class);
return query.getResultList();
}
}
Movie entity class:
/**
* The persistent class for the movies database table.
*
*/
#Entity(name="Movie")
#Table(name="movies")
#NamedQuery(name="Movie.findAll", query="SELECT m FROM Movie m")
public class Movie implements Serializable {
private static final long serialVersionUID = 1L;
private int movieid;
private String imdbid;
#Column(name = "title")
private String title;
private String year;
private List<Akatitle> akatitles;
private List<Director> directors;
private List<Distributor> distributors;
private List<Editor> editors;
private List<Genre> genres;
private List<Keyword> keywords;
private List<Language> languages;
private List<Literature> literatures;
private List<Location> locations;
private List<Actor> actors;
private List<Composer> composers;
private List<Writer> writers;
private List<Mpaarating> mpaaratings;
private List<Plot> plots;
private List<Prodcompany> prodcompanies;
private List<Producer> producers;
private List<Quote> quotes;
private List<Rating> ratings;
private List<Releasedate> releasedates;
private List<Runningtime> runningtimes;
private List<Soundtrack> soundtracks;
private List<Tagline> taglines;
private List<Technical> technicals;
private List<Trivia> trivias;
public Movie() {
}
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
public int getMovieid() {
return this.movieid;
}
public void setMovieid(int movieid) {
this.movieid = movieid;
}
public String getImdbid() {
return this.imdbid;
}
public void setImdbid(String imdbid) {
this.imdbid = imdbid;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getYear() {
return this.year;
}
public void setYear(String year) {
this.year = year;
}
//bi-directional many-to-one association to Akatitle
#OneToMany(mappedBy="movie")
#JoinColumn(name="movieid")
public List<Akatitle> getAkatitles() {
return this.akatitles;
}
public void setAkatitles(List<Akatitle> akatitles) {
this.akatitles = akatitles;
}
public Akatitle addAkatitle(Akatitle akatitle) {
getAkatitles().add(akatitle);
akatitle.setMovie(this);
return akatitle;
}
public Akatitle removeAkatitle(Akatitle akatitle) {
getAkatitles().remove(akatitle);
akatitle.setMovie(null);
return akatitle;
}
//...
}
Here is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="MovieTime" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/movietime2"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
</properties>
</persistence-unit>
</persistence>
spring-servlet.xml file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- Use #Component annotations for bean definitions -->
<context:component-scan base-package="com.movietime" />
<!-- Use #Controller annotations for MVC controller definitions -->
<mvc:annotation-driven enable-matrix-variables="true"/>
<!-- View resolver -->
<bean class=
"org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp" />
</bean>
<!-- Defining the dataSource -->
<bean id="dataSource" name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/movietime2" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<!-- Necessary to get the entity manager injected into the factory bean -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<!-- Define EclipseLink JPA Vendor Adapter -->
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform"
value="org.eclipse.persistence.platform.database.MySQLPlatform" />
<property name="generateDdl" value="false" />
<property name="showSql" value="true" />
</bean>
<!-- Setting up JPA Entity Manager Factory -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
<property name="packagesToScan" value="com.movietime.entities" />
<property name="persistenceUnitName" value="MovieTime"></property>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="dataSource" ref="dataSource"/>
<!--
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
-->
</bean>
<!-- Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
<!-- Detect #Transactional -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
You have not specified the name of the persistence unit to use within your annotation, which should then use a "default" persistence unit. Try specifying your "MovieTime" persistence unit instead:
#PersistenceContext(unitName="MovieTime")
private EntityManager em;

Resources