Spring & Hibernate don't save my records in database - database

I've read many topics with the same problem like my but it didn't solved so I've decided write here.
The problem is that when I want to edit or delete record in my project, every function implemented in Java seems to run correctly, but there aren't any changes in database.
For example in my project I've got model called 'Oddzial' (in english it's department).
I can add new Oddzial (Department) to the database and I'll see the changes. But if I want to delete everything, there aren't any errors but also there aren't any changes in database. The record which should be deleted is still in database.
Here are my files:
Model:
#Entity
#Table(name="oddzial")
public class Oddzial implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue
private Integer oddzial_id;
#Size(min=3, max=25, message="test message.")
private String miasto;
#Size(min=5, max=50, message="test message.")
private String ulica;
public Integer getOddzial_id() {
return oddzial_id;
}
public void setOddzial_id(Integer oddzial_id) {
this.oddzial_id = oddzial_id;
}
public Integer getId() {
return oddzial_id;
}
public void setId(Integer id_oddzial) {
this.oddzial_id = id_oddzial;
}
public String getMiasto() {
return miasto;
}
public void setMiasto(String miasto) {
this.miasto = miasto;
}
public String getUlica() {
return ulica;
}
public void setUlica(String ulica) {
this.ulica = ulica;
}
#Override
public String toString() {
return "[" + oddzial_id + "] " + ulica + " " + miasto;
}
}
Here is Oddzial's DAO:
#Repository
public class OddzialDAOImpl implements OddzialDAO {
#Autowired
private SessionFactory sessionFactory;
private Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}
public void addOddzial(Oddzial oddzial) {
getCurrentSession().save(oddzial);
}
public void updateOddzial(Oddzial oddzial) {
Oddzial oddzialToUpdate = getOddzial(oddzial.getId());
oddzialToUpdate.setMiasto(oddzial.getMiasto());
oddzialToUpdate.setUlica(oddzial.getUlica());
getCurrentSession().update(oddzialToUpdate);
}
public Oddzial getOddzial(int id) {
Oddzial oddzial = (Oddzial) getCurrentSession().get(Oddzial.class, id);
return oddzial;
}
public void deleteOddzial(int id) {
Oddzial oddzial = getOddzial(id);
if (oddzial != null)
getCurrentSession().delete(oddzial);
}
#SuppressWarnings("unchecked")
public List<Oddzial> getOddzialy() {
return getCurrentSession().createQuery("from Oddzial").list();
}
}
Here is OddzialService:
#Service
#Transactional
public class OddzialServiceImpl implements OddzialService {
#Autowired
private OddzialDAO oddzialDAO;
#Override
public void addOddzial(Oddzial oddzial) {
oddzialDAO.addOddzial(oddzial);
}
#Override
public void updateOddzial(Oddzial oddzial) {
oddzialDAO.updateOddzial(oddzial);
}
#Override
public Oddzial getOddzial(int id) {
return oddzialDAO.getOddzial(id);
}
#Override
public void deleteOddzial(int id) {
oddzialDAO.deleteOddzial(id);
}
#Override
public List<Oddzial> getOddzialy() {
return oddzialDAO.getOddzialy();
}
}
And here is Controller:
#Controller
#RequestMapping(value="/oddzial")
public class OddzialController {
#Autowired
private OddzialService oddzialService;
#RequestMapping(value="/add", method=RequestMethod.GET)
public ModelAndView addOddzialPage() {
ModelAndView modelAndView = new ModelAndView("add-oddzial-form");
modelAndView.addObject("oddzial", new Oddzial());
return modelAndView;
}
#RequestMapping(value="/add", method=RequestMethod.POST)
public String addingOddzial(#ModelAttribute #Valid Oddzial oddzial, BindingResult result) {
if(result.hasErrors()) {
return "add-oddzial-form";
}
oddzialService.addOddzial(oddzial);
String message = "Oddział został pomyślnie dodany do bazy.";
return "list-of-oddzials";
}
#RequestMapping(value="/list")
public ModelAndView listOfOddzials() {
ModelAndView modelAndView = new ModelAndView("list-of-oddzials");
List<Oddzial> oddzials = oddzialService.getOddzialy();
modelAndView.addObject("oddzials", oddzials);
return modelAndView;
}
#RequestMapping(value="/edit/{id}", method=RequestMethod.GET)
public ModelAndView editOddzialPage(#PathVariable Integer id) {
ModelAndView modelAndView = new ModelAndView("edit-oddzial-form");
Oddzial oddzial = oddzialService.getOddzial(id);
modelAndView.addObject("oddzial",oddzial);
return modelAndView;
}
#RequestMapping(value="/edit/{id}", method=RequestMethod.POST)
public ModelAndView edditingOddzial(#ModelAttribute Oddzial oddzial, #PathVariable Integer id) {
ModelAndView modelAndView = new ModelAndView("home");
oddzialService.updateOddzial(oddzial);
String message = "Dane zostały zmodyfikowane.";
modelAndView.addObject("message", message);
return modelAndView;
}
#RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
public ModelAndView deleteOddzial(#PathVariable Integer id) {
ModelAndView modelAndView = new ModelAndView("home");
oddzialService.deleteOddzial(id);
String message = "Oddział został usunięty.";
modelAndView.addObject("message", message);
return modelAndView;
}
}
The content of my Spring configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:flow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
<!-- Root Context: defines shared resources visible to all other web components -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/tutorial" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="pl.carrental" />
<property name="hibernateProperties">
<props>
<prop key="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="passwordEncoder"
class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">
<constructor-arg value="256" />
</bean>
<bean id="saltSource"
class="org.springframework.security.authentication.dao.ReflectionSaltSource">
<property name="userPropertyToUse" value="username" />
</bean>
<!-- <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry"></property> </bean> <bean
class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> <property
name="flowExecutor" ref="flowExecutor"></property> </bean> <flow:flow-executor
id="flowExecutor" flow-registry="flowRegistry" /> <flow:flow-registry id="flowRegistry"
base-path="/WEB-INF/flows"> <flow:flow-location-pattern value="/**/*-flow.xml"
/> </flow:flow-registry> -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
<bean
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan
base-package="pl.carrental" />
The content of web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
/WEB-INF/spring/spring-security.xml
</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>localizationFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>localizationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Thanks in advance for help

SOLVED. The line:
<tx:annotation-driven transaction-manager="transactionManager" />
must be in servlet-context.xml. Not in root-config.xml like in my case. Now transactions are committed and I can delete and update records.

Related

JPA NamedQuery not found

I'm trying to get a list of persons using JPA. Every time I run the code, I get "java.lang.IllegalArgumentException: NamedQuery of name: Persoon.getAllePersonen not found."
I tried changing the table name, replaced Persoon.getAllePersonen by getAllePersonen,.... I just can't seem to figure out what's causing the error
Persoon
#Entity
#Table(name = "Persoon")
#NamedQueries({
#NamedQuery(name = "Persoon.getAllePersonen",
query = "SELECT p FROM Persoon p"),
#NamedQuery(name = "Persoon.findByName",
query = "SELECT p FROM Persoon p WHERE p.achternaam = :persoonNaam OR p.voornaam = :persoonNaam")
})
public class Persoon implements Serializable {
PersoonDao
public List<Persoon> getAlleLeden(){
TypedQuery<Persoon> queryP = em.createNamedQuery("Persoon.getAllePersonen", Persoon.class);
try{ return queryP.getResultList();
} catch (NoResultException e){
throw new EntityNotFoundException("Cannot find leden");
}
}
EDIT:
Generic Superclass DAO
public class GenericDaoJpa<T>{
private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("TaijitanPU");
protected static final EntityManager em = emf.createEntityManager();
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="TaijitanPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>domein.Persoon</class>
<class>domein.Graad</class>
<class>domein.Locatie</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost\sqlexpress:1433;databaseName=Taijitan;integratedSecurity=true;"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
You have to do an abstract class Generic class and override the entityManager of the parent class for each child. Check below. I used EJB Stateless for the childs.
-> PARENT DAO
public abstract class AbstractDAO<T> {
...
protected abstract EntityManager getEntityManager();
-> CHILD DAO
#PersistenceContext(unitName = "yourPersistenceUnitName")
private EntityManager em;
#Override
protected EntityManager getEntityManager() {
return em;
}

How to send json from spring-mvc controller to angularjs

I am trying to develop a simple application using angularjs and spring mvc restful web service. At first, I have to load the index file where it makes an http call http://localhost:8088/angular/demo to get some json data from the server. But I get a 406 not acceptable error for this.
The first method in the controller, I have written to load the main page and the second method should respond with user information as JSON.
Is it wrong to have a method returning modelAndView and another returning data in the same controller?
If I use only methods serving JSON data in the controller, then how should I load the first page?
I have included all the required libraries in the lib folder.
In index.jsp i have:
$scope.displayUsers=function(){
$http({
method : 'GET',
url : urlBase+'/demo'
}).success(function(response) {
var response = JSON.parse(response)
alert(response);
console.log(response);
});
}
//---call the display users method
$scope.displayUsers();
The controller is :
#RestController
public class Controller {
#RequestMapping("/")
public ModelAndView helloWorld()
{
ModelAndView model=new ModelAndView("index");
model.addObject("msg", "Hello World");
return model;
}
#RequestMapping(value="/demo", method = RequestMethod.GET)
public #ResponseBody List<Data> getAllTasks() {
List<Data> tasks=new ArrayList<Data>() ;
Data data=new Data();
data.setName("Abc");
data.setEmail("abc#xyz.com");
tasks.add(data);
return tasks;
}
}
The resource representation class is:
public class Data {
String name;
String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
web.xml:
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Angular Rest Spring</display-name>
<servlet>
<servlet-name>angular</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>angular</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
angular-servlet.jsp :
<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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<context:component-scan base-package="com.gitanjal.angular"/>
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>

JPA not generating tables from entities

Here is some entity:
#Entity
public class Forest {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private long id;
public Forest() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
I want to insert some element in table forest:
public class Main {
private static EntityManagerFactory emf =
Persistence.createEntityManagerFactory("server");
public static void main(String[] args) {
EntityManager em = emf.createEntityManager();
EntityTransaction trx = em.getTransaction();
Forest forest = new Forest();
trx.begin();
em.persist(forest);
trx.commit();
}
}
Thrown exception:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: Table 'server.forest' doesn't exist
Caused by: org.hibernate.exception.SQLGrammarException: Table 'server.forest' doesn't exist
My persistence.xml file with settings:
<?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="server">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/server"/>
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
When I removed #GeneratedValue(strategy = GenerationType.AUTO) and set id for forest:
forest.setID(1), there was no exception and table has been generated. So, auto-generating of id is not working and I don't know why.
According configuration there is org.hibernate.dialect.HSQLDialect used with MySQL database. Using MySQL dialect instead of one of HSQL likely helps. Likely InnoDB is used - if so, then MySQL5InnoDBDialect is way to go.

JPA + Google SQL + GWT + Eclipse

I'm trying to run a simple project.
I'm struggling with some issues.
I created a simple table in a database instance.
Then, following google tutorial, I set up my project in Eclipse.
I raise this error on running from localhost:
[EL Severe]: 2012-11-23 14:23:16.915--ServerSession(1241461653)--Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------
Exception [EclipseLink-60] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [set] or [get] is not defined in the object [com.shared.Main].
Internal Exception: java.lang.NoSuchMethodException: com.shared.Main.get(java.lang.String)
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[id-->main.ID]
Descriptor: RelationalDescriptor(com.shared.Main --> [DatabaseTable(main)])
Exception [EclipseLink-60] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [set] or [get] is not defined in the object [com.shared.Main].
Internal Exception: java.lang.NoSuchMethodException: com.shared.Main.get(java.lang.String)
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[name-->main.NAME]
Descriptor: RelationalDescriptor(com.shared.Main --> [DatabaseTable(main)])
It seems that eclipse link can't find getter and setter for my object...
Any clue?
My persistence.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence 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_1_0.xsd" version="1.0">
<persistence-unit name="transactions-optional" transaction-type="RESOURCE_LOCAL">
<provider></provider>
<mapping-file>META-INF/eclipselink-orm.xml</mapping-file>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="datanucleus.ConnectionURL" value="appengine"/>
<property name="javax.persistence.jdbc.driver" value="com.google.appengine.api.rdbms.AppEngineDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:google:rdbms://myinstance/test_jpa"/>
<property name="javax.persistence.jdbc.user" value="myuser"/>
<property name="javax.persistence.jdbc.password" value="mypassword"/>
</properties>
</persistence-unit>
</persistence>
My eclipse-orm.xml:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.4" xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_4.xsd">
<entity class="com.shared.Main" access="VIRTUAL">
<attributes>
<id name="id" attribute-type="int">
<generated-value strategy="AUTO"/>
</id>
<basic name="name" attribute-type="String">
</basic>
</attributes>
</entity>
</entity-mappings>
My Object:
package com.shared;
import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the main database table.
*
*/
#Entity
#Table(name="main")
public class Main implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(unique=true, nullable=false)
private int id;
#Column(length=50)
private String name;
public Main() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
Your shared folder exists (also) on client. The client can not know anything about databases. SQL etc. Remove all database relations from shared to server.
The problem was solved removing the link to the orm file in persistance.xml:
<mapping-file>META-INF/eclipselink-orm.xml</mapping-file>
and adding direct mapping to classes
<class>org.my.package.MyClass</class>

mandatory request param in cxf

I developed a web service with CXF and It work fine.
I have a service with two input parameters and both of them should be mandatory.
but when I call my service just the first parameter is mandatory.
please let me know what should I do?
my SEI
#WebService(
endpointInterface = "com.myCompany.product.webService",
targetNamespace = "http://product.myCompany.com",
portName = "product",
serviceName = "ProductService")
#DataBinding(org.apache.cxf.aegis.databinding.AegisDatabinding.class)
public interface ProductService {
#WebMethod(operationName = "authentication")
#WebResult(name = "authenticationResponseParam")
public AuthenticationResponseParam authentication(#WebParam(name = "user", header = true) String user,
#WebParam(name = "authenticationRequestParam") AuthenticationRequestParam authenticationRequestParam);
}
and my AuthenticationResponseParam class
#XmlAccessorType(XmlAccessType.FIELD
)
#XmlType(name = "authenticationRequestParam", propOrder = {
"account", "password"
})
public class AuthenticationRequestParam implements Serializable {
#XmlElement(name = "account", required = true)
private BigDecimal account;
#XmlElement(name = "password", required = true)
private String password;
public BigDecimal getAccount() {
return account;
}
public void setAccount(BigDecimal account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
#Override
public String toString() {
return "AuthenticationRequestParam{" +
"account=" + account +
", password='" + password + '\'' +
'}';
}
}
and my CXF servlet xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
<!--Data binding-->
<bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding" scope="prototype"/>
<bean id="jaxws-and-aegis-service-factory"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
scope="prototype">
<property name="dataBinding" ref="aegisBean"/>
</bean>
<jaxws:endpoint id="telBank" implementor="#myService" address="/telBank">
<jaxws:binding>
<soap:soapBinding mtomEnabled="false" version="1.2"/>
</jaxws:binding>
</jaxws:endpoint>
<bean id="myService" class="com.myCompany.product.webService.impl.ProductServiceImpl"/>
</beans>
thank you
Hey guys
I added a new service in my web service
public BigDecimal sample(#WebParam(name = "sam1") BigDecimal a1,#WebParam(name = "sam2") BigDecimal a2);
and none of both parameters are mandatory
what should I do?please help me
I found what my problem.
I use org.apache.cxf.aegis.databinding.AegisDatabinding az data binder and it just recognize primitive type az mandatory.when I commend that my input param become mandatory.
what kind of data binder should I use?
If you want to use AegisDatabinding class as data binder,set this property it bean definition.
<bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding" scope="prototype">
<property name="configuration">
<bean class="org.apache.cxf.aegis.type.TypeCreationOptions">
<property name="defaultMinOccurs" value="1"/>
<property name="defaultNillable" value="false"/>
</bean>
</property>
</bean>

Resources