schemagen NullpointerException - nullpointerexception

Java class:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "user", propOrder = {
"id",
"name" })
public class User {
#XmlAttribute(required=true)
private long id;
#XmlAttribute(required=true)
private String name;
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;
}
#Override
public String toString() {
return "User [id=" + id + ", name=" + name + "]";
}
}
JDK version : 1.6.0_31
Exception Stack Trace schemagen User.java
C:\anirban\work_eclipse_juno\RestfulWSDemo\src\com\domain>schemagen User.java
An exception has occurred in apt (1.6.0_31). Please file a bug at the Java Devel
oper Connection (http://java.sun.com/webapps/bugreport) after checking the Bug
Parade for duplicates. Include your program and the following diagnostic in your
report. Thank you.
java.lang.NullPointerException
at com.sun.tools.apt.main.CommandLine.parse(CommandLine.java:42)
at com.sun.tools.apt.main.Main.compile(Main.java:775)
at com.sun.tools.apt.Main.processing(Main.java:95)
at com.sun.tools.apt.Main.process(Main.java:85)
at com.sun.tools.apt.Main.process(Main.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.tools.internal.jxc.SchemaGenerator$Runner.main(SchemaGenerato
r.java:215)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.tools.internal.jxc.SchemaGenerator.run(SchemaGenerator.java:1
53)
at com.sun.tools.internal.jxc.SchemaGenerator.run(SchemaGenerator.java:6
3)
at com.sun.tools.internal.jxc.SchemaGenerator.main(SchemaGenerator.java:
55)
Can anyone please help me out here?

Try adding the classpath.
schemagen -cp "%java_home%\lib\tools.jar" User.java

Related

Unable to read the test data from CSV via ThucydidesParameterizedRunner

I am trying to print the value which I am feeding as input inside the CSV file. When run the below set of code through Junit and getting error.
Could some one please help me to come out of this error and print the values successfully
#RunWith(ThucydidesParameterizedRunner.class)
#UseTestDataFrom(value="test-data/simple-data.csv", separator=';')
public class SampleCSVDataDrivenScenario {
private String name;
private String age;
private String address;
public SampleCSVDataDrivenScenario() {
}
#Qualifier
public String getQualifier() {
return name;
}
#Test
public void data_driven() {
System.out.println(getName() + "/" + getAge());
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
Please find the full error log below
java.lang.NoSuchMethodError:
org.junit.runners.model.FrameworkMethod.getDeclaringClass()Ljava/lang/Class;
at net.serenitybdd.junit.runners.SerenityRunner.runChild(SerenityRunner.java:421)
at net.serenitybdd.junit.runners.SerenityRunner.runChild(SerenityRunner.java:55)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at net.serenitybdd.junit.runners.SerenityRunner.run(SerenityRunner.java:252)
at org.junit.runners.Suite.runChild(Suite.java:127)
at org.junit.runners.Suite.runChild(Suite.java:26)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at net.serenitybdd.junit.runners.SerenityParameterizedRunner.run(SerenityParameterizedRunner.java:206)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
And this is how my CSV file looks like
NoSuchMethodError usually indicates a dependency conflict. You are possibly running the tests with an incompatible version of JUnit - make sure you are using the version of JUnit compatible with the version of Serenity you are using (Serenity has been built with JUnit 4.12 for a while now).

How to resolve org.testng.internal.reflect.MethodMatcherException in TestNG?

ContactsPage Class:-
public class ContactsPage extends TestBase {
public ContactsPage()
{
PageFactory.initElements(driver, this);
}
public boolean contactsLabel()
{
return contactsLabel.isDisplayed();
}
public void createNewContact1(String subject, String fName, String lName, String petname ) throws InterruptedException, AWTException
{
.....
}
public void createNewContact2(String comp, String comPos, String dept, String conLookSup ) throws InterruptedException
{
.....
}
public void createNewContact3(String conLookAss, String conLookRef ) throws InterruptedException
{
.....
}
}
ContactsPageTest Class:-
public class ContactsPageTest extends TestBase {
TestUtil testUtil;
LoginPage loginpage;
HomePage homepage;
ContactsPage contactsPage;
String sheetName = "Contacts";
public ContactsPageTest() {
super();
}
#BeforeMethod()
public void setUp() throws InterruptedException {
initialzation();
testUtil = new TestUtil();
loginpage = new LoginPage();
homepage = loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
contactsPage = new ContactsPage();
}
/*
* #Test(priority = 1) public void contactsLabelTest() throws
* InterruptedException { testUtil.switchToFrame(); contactsPage =
* homepage.contactsLink(); Thread.sleep(3000);
* Assert.assertTrue(contactsPage.contactsLabel(), "Exception has caught!"); }
*/
#DataProvider
public Object[][] getCRMTestData() {
Object data[][] = TestUtil.getTestData("Contacts");
return data;
}
#Test(priority = 2, dataProvider = "getCRMTestData")
public void createNewContactTest1(String subject, String fName, String lName, String petname)
throws InterruptedException, AWTException {
testUtil.switchToFrame();
homepage.moveToNewContact();
contactsPage.createNewContact1(subject, fName, lName, petname);
}
#Test(priority = 3, dataProvider = "getCRMTestData")
public void createNewContactTest2(String comp, String comPos, String dept, String conLookSup)
throws InterruptedException, AWTException
{
contactsPage.createNewContact2(comp, comPos, dept, conLookSup);
}
#Test(priority = 4, dataProvider = "getCRMTestData")
public void createNewContactTest3(String conLookAss, String conLookRef)
throws InterruptedException, AWTException
{
contactsPage.createNewContact3(conLookAss, conLookRef);
}
#AfterMethod
public void close() {
driver.close();
}
}
Error Message:
FAILED: createNewContactTest1
org.testng.internal.reflect.MethodMatcherException:
Data provider mismatch
Method: createNewContactTest1([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=2, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=3, type=java.lang.String, declaredAnnotations=[]}])
Arguments: [(java.lang.String) Mr,(java.lang.String) Manideep,(java.lang.String) Latchupatula,(java.lang.String) Deep,(java.lang.String) Accenture,(java.lang.String) ASE,(java.lang.String) CSE,(java.lang.String) TL,(java.lang.String) NA,(java.lang.String) NA]
at org.testng.internal.reflect.DataProviderMethodMatcher.getConformingArguments(DataProviderMethodMatcher.java:45)
at org.testng.internal.Parameters.injectParameters(Parameters.java:796)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:982)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Description: I am working to develop Hybrid Framework by using Selenium. I started off on a positive note but I've been stuck at:
org.testng.internal.reflect.MethodMatcherException.
I have tried for some time but I am clueless. So here, I am.
Could you please let me know where the issue is?
It is throwing MethodMatcherException because you are passing same Data provider to different #Test Method, And Each test method has different Parameter value. Parameters return by #DataProvider and #Test Method should must match in order to retrieve and assign data.
You need to make sure what Data provider is returning, And you can assign it according those Parameters to Test method.
Here your Data Provider is returning Parameters as Following: Its 10
Parameter [Mr,Manideep,Latchupatula,Deep, Accenture, ASE, CSE,TL, NA,
NA]
And You are binding it with 4 Parameters of #Test createNewContactTest1 method:
createNewContactTest1(String subject, String fName, String lName, String petname)
You need to Manage
Your Data provider retrieval code as according to your required Parameters OR
You can create different sheet with required parameters OR
You can add all 10 Parameters to #Test method as according to DP returns

JBoss 7.1 and Hibernte 4.3.5 cause exception

I create a project with Hibernate 4.3.5 and JBoss 7.1.1.
I give you a screenshot about the composition of my project:
The jars on WEB-INF/lib are:
Bellow, are the rquired classes:
EntityDao.java
public class EntityDao implements EntityDaoInterface<Book, Integer>
{
private Session currentSession;
private Transaction currentTransaction;
public EntityDao() {
}
public Session openCurrentSession() {
currentSession = getSessionFactory().openSession();
return currentSession;
}
public Session openCurrentSessionwithTransaction() {
currentSession = getSessionFactory().openSession();
currentTransaction = currentSession.beginTransaction();
return currentSession;
}
public void closeCurrentSession() {
currentSession.close();
}
public void closeCurrentSessionwithTransaction() {
currentTransaction.commit();
currentSession.close();
}
private static SessionFactory getSessionFactory() {
Configuration configuration = new Configuration().configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties());
SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
return sessionFactory;
}
public Session getCurrentSession() {
return currentSession;
}
public void setCurrentSession(Session currentSession) {
this.currentSession = currentSession;
}
public Transaction getCurrentTransaction() {
return currentTransaction;
}
public void setCurrentTransaction(Transaction currentTransaction) {
this.currentTransaction = currentTransaction;
}
public void persist(Person entity) {
getCurrentSession().save(entity);
}
public void update(Person entity) {
getCurrentSession().update(entity);
}
public void delete(Person entity) {
getCurrentSession().delete(entity);
}
#SuppressWarnings("unchecked")
public List<Person> findAllPersons() {
List<Person> persons = (List<Person>) getCurrentSession().createQuery("from Person").list();
return persons;
}
public Person findPersonById(Integer id) {
Person person = (Person) getCurrentSession().get(Person.class, id);
return person;
}
}
EntityDaoInterface.java
public interface EntityDaoInterface<T, Id extends Serializable>
{
public void persist(T entity);
public void update(T entity);
public T findById(Id id);
public void delete(T entity);
public List<T> findAll();
public void deleteAll();
}
EntityService.java
public class EntityService
{
private static EntityDao entityDao;
public EntityService() {
entityDao = new EntityDao();
}
public void persist(Person entity) {
entityDao.openCurrentSessionwithTransaction();
entityDao.persist(entity);
entityDao.closeCurrentSessionwithTransaction();
}
public void update(Person entity) {
entityDao.openCurrentSessionwithTransaction();
entityDao.update(entity);
entityDao.closeCurrentSessionwithTransaction();
}
public void remove(Person entity) {
entityDao.openCurrentSessionwithTransaction();
entityDao.delete(entity);
entityDao.closeCurrentSessionwithTransaction();
}
public Person findPersonById(int id) {
entityDao.openCurrentSession();
Person person = entityDao.findPersonById(id);
entityDao.closeCurrentSession();
return person;
}
public List<Person> findAllPersons() {
entityDao.openCurrentSession();
List<Person> persons = entityDao.findAllPersons();
entityDao.closeCurrentSession();
return persons;
}
public void deleteAll() {
entityDao.openCurrentSessionwithTransaction();
entityDao.deleteAll();
entityDao.closeCurrentSessionwithTransaction();
}
public EntityDao entityDao() {
return entityDao;
}
}
Person.java
#Entity
#Table(name = "person")
public class Person
{
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "id", unique = true, nullable = false)
private int id;
#Column(name = "age")
private int age;
#Column(name= "name")
String name;
public Person() {}
public Person(int id, int age, String name) {
super();
this.id = id;
this.age = age;
this.name = name;
}
// With the methods: set, get, toString, hashCode, equals
}
hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;database=ccc</property>
<property name="hibernate.connection.username">lm</property>
<property name="hibernate.connection.password">pp</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping class="com.esprit.entity.Book"/>
<mapping class="com.esprit.entity.Person"/>
</session-factory>
</hibernate-configuration>
DataModelBeanD.java
#SuppressWarnings("serial")
#ManagedBean
#ViewScoped
public class DataModelBeanD implements Serializable
{
private List<Person> list;
private Person person = new Person();
private boolean edit;
private EntityService entityService;
#PostConstruct
public void init()
{
entityService = new EntityService();
list = entityService.findAllPersons();
}
}
After running the project, the following error appears:
08:32:54,297 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "HelloJPAHibernate.war"
08:33:01,282 INFO [org.hibernate.annotations.common.Version] (http-localhost-127.0.0.1-8080-1) HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
08:33:01,290 INFO [org.hibernate.Version] (http-localhost-127.0.0.1-8080-1) HHH000412: Hibernate Core {4.3.5.Final}
08:33:01,293 INFO [org.hibernate.cfg.Environment] (http-localhost-127.0.0.1-8080-1) HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
08:33:01,297 INFO [org.hibernate.cfg.Environment] (http-localhost-127.0.0.1-8080-1) HHH000021: Bytecode provider name : javassist
08:33:01,317 INFO [org.hibernate.cfg.Configuration] (http-localhost-127.0.0.1-8080-1) HHH000043: Configuring from resource: /hibernate.cfg.xml
08:33:01,318 INFO [org.hibernate.cfg.Configuration] (http-localhost-127.0.0.1-8080-1) HHH000040: Configuration resource: /hibernate.cfg.xml
08:33:01,366 INFO [org.hibernate.cfg.Configuration] (http-localhost-127.0.0.1-8080-1) HHH000041: Configured SessionFactory: null
08:33:01,453 WARN [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost-127.0.0.1-8080-1) HHH000402: Using Hibernate built-in connection pool (not for production use!)
08:33:01,455 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost-127.0.0.1-8080-1) HHH000401: using driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] at URL [jdbc:sqlserver://localhost:1433;database=ccc]
08:33:01,457 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost-127.0.0.1-8080-1) HHH000046: Connection properties: {user=lm, password=****}
08:33:01,458 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost-127.0.0.1-8080-1) HHH000006: Autocommit mode: false
08:33:01,460 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost-127.0.0.1-8080-1) HHH000115: Hibernate connection pool size: 5 (min=1)
08:33:03,123 INFO [org.hibernate.dialect.Dialect] (http-localhost-127.0.0.1-8080-1) HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
08:33:03,255 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/HelloJPAHibernate].[Faces Servlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:936) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3788) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3742) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at com.esprit.dao.EntityDao.getSessionFactory(EntityDao.java:48) [classes:]
at com.esprit.dao.EntityDao.openCurrentSession(EntityDao.java:25) [classes:]
at com.esprit.dao.EntityService.findAllPersons(EntityService.java:86) [classes:]
at com.esprit.crud.dynamic.DataModelBeanD.init(DataModelBeanD.java:37) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_55]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_55]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_55]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_55]
I couldn't know what's missed, could you please help me solving this issue. Any proposition is appreciated.Thanks in advance.
I solved my problem by making Hibernate 4.2.21 instead of Hibernate 4.3.5. Then I re-create the method getSessionFactory() of the class EntityDao.java like bellow:
private static SessionFactory getSessionFactory()
{
if (sessionFactory == null) {
Configuration configuration = new Configuration().configure();
ServiceRegistryBuilder registry = new ServiceRegistryBuilder();
registry.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = registry.buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
return sessionFactory;
}

Getting class cast exception when doing a POST request using JAX-RS with hibernate backend

I have a simple User POJO class, its definition is as follows:
package models;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#Entity
#XmlRootElement
#Table(name="USER",uniqueConstraints={#UniqueConstraint(columnNames="email")})
public class User {
#XmlElement
private String name;
#Id
#XmlElement
#GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
#XmlElement
private String email;
#XmlElement
private int age;
#Override
public String toString() {
return "User [name=" + name + ", id=" + id + ", email=" + email + ", age=" + age + "]";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
and my resource mapping is as follows:
#POST
#Produces(MediaType.TEXT_HTML)
#Consumes(MediaType.APPLICATION_JSON)
#Path("/Person")
public Response insertPerson(User user) {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
int uid = (Integer)session.save(user);
tx.commit();
session.close();
return Response.status(201).entity(uid).build();
}
When i do a post request using PostMan i am getting this exception on server:
Dec 20, 2015 9:44:42 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Jersey Web Application] in context with path [/expenseManagement] threw exception [Exception [EclipseLink-6065] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.QueryException
Exception Description: Cannot add the object [User [name=manjunath, id=100, email=manjunath#gmail.com, age=15]], of class [class models.User], to container [class models.User].
Internal Exception: java.lang.ClassCastException: models.User cannot be cast to java.util.Collection] with root cause
java.lang.ClassCastException: models.User cannot be cast to java.util.Collection
I have provided message body readers as well, I don't know where i am going wrong, can someone please help.
The content you send is surrounded by [ and ] marking it an array, not an object. Try sending only this String:
{"name":"manjunath", "age":15, "id":100, "email":"manjunath#gmail.com"}
Good Luck

Getting org.apache.cxf.jaxrs.ext.search.PropertyNotFoundException when parsing fiql expression containing java.util.Calendar attribute

I use FIQL to query a web service built using Apache CXF 3.0.0-milestone1. When I attempt to reference any attribute of type java.util.Calendar I get a org.apache.cxf.jaxrs.ext.search.PropertyNotFoundException. I have tracked down the behavior to the FiqlParser.parse(String expression) call and I am able to reproduce it with the simple code below.
Search bean :
import java.util.Calendar;
import java.util.Date;
public class Book {
private Long id;
private String title;
private Date published;
private Calendar created;
public Book() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getPublished() {
return published;
}
public void setPublished(Date published) {
this.published = published;
}
public Calendar getCreated() {
return created;
}
public void setCreated(Calendar created) {
this.created = created;
}
}
Executable class :
import org.apache.cxf.jaxrs.ext.search.SearchCondition;
import org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser;
public class PlayGround {
public static void main(String[] args) {
FiqlParser<Book> parser = new FiqlParser(Book.class);
SearchCondition<Book> condition1 = parser.parse("id=ge=0");
SearchCondition<Book> condition2 = parser.parse("title==*wind*");
SearchCondition<Book> condition3 = parser.parse("published=ge=2014-01-01");
SearchCondition<Book> condition4 = parser.parse("created=ge=2013-01-01");
}
}
PlayGround fails on the following line :
SearchCondition<Book> condition4 = parser.parse("created=ge=2013-01-01");
Stack trace:
Exception in thread "main" org.apache.cxf.jaxrs.ext.search.PropertyNotFoundException
at org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser.parseComparison(FiqlParser.java:294)
at org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser.parseAndsOrsBrackets(FiqlParser.java:252)
at org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser.parse(FiqlParser.java:187)
at PlayGround.main(PlayGround.java:18)
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:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
If you put a breakpoint in catch block in method org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser.parseType(String, String, String) you'll see this message for the exception:
org.apache.cxf.jaxrs.ext.search.SearchParseException: Cannot convert String value "2013-01-01" to a value of class java.util.Calendar