XML to ArrayList Java Rest Application - java

This is my first project with JEE/Rest applications
My problem is that I just can't get my server to parse an xml post to my object wich contains an ArrayList...
Here is where I handle the #POST, the server just returns what it gets:
Search.java
#POST
#Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
#Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Request returnRequest(Request input) {
return input;
}
When I post this:
<request>
<name>Salle 101</name>
<equipments>
<equipment>
<rfName>Tableau Blanc</rfName>
</equipment>
<equipment>
<rfName>Video Projecteur</rfName>
</equipment>
</equipments>
<startslot>9</startslot>
<endslot>10</endslot>
<size>6</size>
<site>Toulouse</site>
</request>
I get this:
<?xml version="1.0" encoding="UTF-8"?>
<request>
<endslot>10</endslot>
<equipments/>
<name>Salle 101</name>
<site>Toulouse</site>
<size>6</size>
<startslot>9</startslot>
</request>
As you can see I don't have my equipment list correctly returned...
Here are my entity files:
Request.java
#XmlRootElement(name = "request")
public class Request {
//#XmlElement
private String name;
//#XmlElement
private Equipments equipments;
//#XmlElement
private int startSlot;
//#XmlElement
private int endSlot;
//#XmlElement
private int size;
//#XmlElement
private String site;
public Request(){
// my stuff
}
// getters & setters
Equipment.java
#Entity
#Table(name = "equipment")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Equipment.findAll", query = "SELECT e FROM Equipment e"),
#NamedQuery(name = "Equipment.findByRfName", query = "SELECT e FROM Equipment e WHERE e.rfName = :rfName")})
public class Equipment implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 20)
#Column(name = "RF_NAME")
private String rfName;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "equipment")
private Collection<RoomEquipment> roomEquipmentCollection;
public Equipment() {
}
public Equipment(String rfName) {
this.rfName = rfName;
}
//...
After a little bit of searching I saw that creating a class for the ArrayList could be useful, so here it is:
Equipments.java
#XmlRootElement(name="equipments")
public class Equipments implements Serializable {
private ArrayList<Equipment> equipments;
public Equipments(){
this.equipments = new ArrayList<>();
}
public void add(Equipment eq){
this.getEquipments().add(eq);
}
public ArrayList<Equipment> getEquipments(){
return this.equipments;
}
/**
* #param equipments the equipments to set
*/
public void setEquipments(ArrayList<Equipment> equipments) {
this.equipments = equipments;
}
}
Thanks for your help

I finally found how do deal with it. It's just that I didn't really understood how #annotations were working...
This website helped me to figure it out: http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html

Related

Trigger #OneToMany lazy fetch

I have an ExampleRequest entity that can optionally have one or more ExampleRequestYear. It's currently configured this way (unrelated fields and gettters/setters omitted for brevity, please let me know if you need anything else):
#Entity
#Table(name = "EXAMPLE_REQUEST")
#SequenceGenerator(name = "EXAMPLE_REQUEST_ID_SEQ", sequenceName = "EXAMPLE_REQUEST_ID_SEQ", allocationSize = 1)
#Cacheable(false)
public class ExampleRequest implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EXAMPLE_REQUEST_ID_SEQ")
#Column(name="EXAMPLE_REQUEST_ID", nullable = false)
private Long exampleRequestId;
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "exampleRequest")
private List<ExampleRequestYear> exampleRequestYearList;
public ExampleRequest() {
}
public List<ExampleRequestYear> getExampleRequestYearList() {
if(this.exampleRequestYearList == null){
this.exampleRequestYearList = new ArrayList<ExampleRequestYear>();
}
return this.exampleRequestYearList;
}
public void setExampleRequestYearList(List<ExampleRequestYear> exampleRequestYearList) {
this.exampleRequestYearList = exampleRequestYearList;
}
public ExampleRequestYear addExampleRequestYear(ExampleRequestYear exampleRequestYear) {
getExampleRequestYearList().add(exampleRequestYear);
exampleRequestYear.setExampleRequest(this);
return exampleRequestYear;
}
public ExampleRequestYear removeExampleRequestYear(ExampleRequestYear exampleRequestYear) {
getExampleRequestYearList().remove(exampleRequestYear);
exampleRequestYear.setExampleRequest(null);
return exampleRequestYear;
}
}
#Entity
#Table(name = "EXAMPLE_REQUEST_YEAR")
#IdClass(ExampleRequestYearPK.class)
public class ExampleRequestYear implements Serializable {
#Id
#Column(nullable = false)
private Integer year;
#Id
#ManyToOne
#JoinColumn(name = "EXAMPLE_REQUEST_ID", referencedColumnName = "EXAMPLE_REQUEST_ID")
private ExampleRequest exampleRequest;
public ExampleRequestYear() {
}
public void setExampleRequest(ExampleRequest exampleRequest) {
this.exampleRequest = exampleRequest;
}
public ExampleRequest getExampleRequest() {
return exampleRequest;
}
}
Part of the code was auto-generated by the IDE and I'm still wrapping my head around JPA so there're probably design mistakes all around.
My app works (apparently) when I create a new ExampleRequest:
ExampleRequest exampleRequest = new ExampleRequest();
ExampleRequestYear exampleRequestYear = new ExampleRequestYear(2020);
request.addExampleRequestYear(exampleRequestYear);
However, I can't figure out how to edit an existing ExampleRequest because I'm unsure on how I'm meant to retrieve the linked entities. According to articles I've read, lazy fetching should be automatic, yet when I try this:
ExampleRequest exampleRequest = employeeRequestsController.getExampleRequestById(123);
System.out.println(exampleRequest.getExampleRequestYearList().size());
... I get a null pointer exception upon .size() because the getter runs but neither initialises an empty list, nor retrieves items from DB:
public List<ExampleRequestYear> getExampleRequestYearList() {
if(this.exampleRequestYearList == null){
// Field is null and conditional is entered
this.exampleRequestYearList = new ArrayList<ExampleRequestYear>();
// After initialisation, field is still null!
}
return this.exampleRequestYearList;
}
Also, switch to FetchType.EAGER solves this particular problem entirely. What am I missing?
Further details regarding app design. The Resource classes that handle HTTP requests interact with a set of Controller classes like this:
#Stateless(name = "ISomeActionController", mappedName = "ISomeActionController")
public class SomeActionController implements ISomeActionController {
#EJB
private IFooDAO fooDao;
#EJB
private IBarDAO barDao;
#Override
public ExampleRequest getExampleRequestById(Long exampleRequestId) {
return fooDao.getEntityById(exampleRequestId);
}
}
It's in the DAO classes where EntityManager is injected an used:
#Local
public interface IGenericDAO<T> {
public T persistEntity(T o);
public T persistEntityCommit(T o);
public void removeEntity(T o);
public void removeEntity(long id);
public T mergeEntity(T o);
public List<T> getEntitiesFindAll();
public List<T> getEntitiesFindAllActive();
public T getEntityById(Object id);
}
public interface IFooDAO extends IGenericDAO<ExampleRequest> {
public void flushDAO();
public ExampleRequest getExampleRequestById(Long exampleRequestId);
}
#Stateless(name = "IFooDAO", mappedName = "IFooDAO")
public class FooDAO extends GenericDAO<ExampleRequest> implements IFooDAO {
public FooDAO() {
super(ExampleRequest.class);
}
#Override
public void flushDAO(){
em.flush();
}
#Override
public ExampleRequest getExampleRequestById(Long exampleRequestId){
String sql = "...";
Query query = em.createNativeQuery(sql, ExampleRequest.class);
//...
}
}

How to send only the ID the of main nested objects in the body request in spring boot

I'm creating eCommerce for merchants using spring boot with JPA.
I have an issue while creating the order service.
I want to only pass the ID of the nested objects in the request body instead of sending the full nest objects because the size will be extremely big.
Here is my code.
Merchant can do many orders
Order
#Entity
#Table(name = "Orders")
#XmlRootElement
#JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Order extends BasicModelWithIDInt {
#Basic(optional = false)
#Column(name = "Quantity")
private Integer quantity;
#Basic(optional = false)
#Size(min = 1, max = 150)
#Column(name = "Notes")
private String notes;
#JoinColumn(name = "ProductID", referencedColumnName = "ID")
#ManyToOne(optional = false, fetch = FetchType.LAZY)
#JsonIgnoreProperties
private Product productID;
#JoinColumn(name = "MerchantID", referencedColumnName = "ID")
#ManyToOne(optional = false, fetch = FetchType.LAZY)
private Merchent merchent;
#JoinColumn(name = "OrderSatusID", referencedColumnName = "ID")
#ManyToOne(optional = false, fetch = FetchType.EAGER)
private OrderStatus orderStatus;
// Getters and Setters
}
Order Holder
public class OrderHolder {
#NotNull
private Order order;
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
}
OrderRepo
public interface OrderRepo extends JpaRepository<Order, Integer> {
}
Order Controller
#RestController
#RequestMapping(value = "order", produces = MediaType.APPLICATION_JSON_VALUE)
public class OrderRestController extends BasicController<OrderHolder>{
#Autowired
private OrderRepo orderRepo;
#PostMapping("create")
public ResponseEntity<?> create(#RequestBody #Valid OrderHolder orderHolder, Principal principal) throws GeneralException {
log.debug( "create order {} requested", orderHolder.toString());
Order order = new Order();
order = orderHolder.getOrder();
System.out.println("###############"+order);
try {
order = orderRepo.save(order);
log.info( "Order {} has been created", order );
} catch (Exception e) {
log.error( "Error creating Order: ", e );
e.printStackTrace();
throw new GeneralException( Errors.ORDER_CREATION_FAILURE, e.toString() );
}
return ResponseEntity.ok( order );
}
}
I need request body to look like the below instead of including the full Merchant and Product objects inside the request.
You can make use of JsonView to return only id of product and merchant
public class OrderView {}
...
public class Product{
#Id
#JsonView(OrderView.class)
private Integer id
private String otherFieldWithoutJsonView
...
}
and then in your controller
#PostMapping("create")
#JsonView(OrderView.class) // this will return the product object with one field (id)
public ResponseEntity<?> create(#RequestBody #Valid OrderHolder orderHolder, Principal principal) throws GeneralException {
...
}
hope this can help you
Just have a separate contract class.
public class OrderContract {
private int merchantID;
private String notes;
....
//getter, setters
}
public class OrderHolder {
#NotNull
private OrderContract orderContract;
public OrderContract getOrderContract() {
return orderContract;
}
public void setOrder(OrderContract orderContract) {
this.orderContract = orderContract;
}
}
And before making a call to the Repository , translate from OrderContract to Order.
I would like to share something regarding this.
I have searched a lot on internet and tried lot of things, but the solution given here suited well for this scenario.
https://www.baeldung.com/jackson-deserialization
You need to create a Custom-deserializer for your model by extending StdDeserializer from com.fasterxml.jackson.databind.deser.std.StdDeserializer, where you just want to pass id's and not the whole object in the request.
I have given below example for User Model with Address object.
User(long userId, String name, Address addressId)
Address(long addressId, String wholeAddress)
Writing Deserializer for User class
public class UserDeserializer extends StdDeserializer<User> {
public User() {
this(null);
}
public User Deserializer(Class<?> vc) {
super(vc);
}
#Override
public User deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
JsonNode node = p.getCodec().readTree(p);
long id = 0;
long addressId = (Long) ((IntNode) node.get("addressId")).numberValue().longValue();
return new User(id, name, new Address(addressId, null)
}
Now you have to use
#JsonDeserialize(using = UserDeserializer.class)
public Class User {
...
}
POST request
Before custom deserialization
{
"name" : "Ravi",
"addressId" : { "id" : 1}
}
After custom Deserialization
{
"name" : "Ravi",
"addressId" : 1
}
Also while GET /user/:id call you will get the whole obj like
{
"name" : "Ravi",
"addressId" : { "id" : 1, "wholeAddress" : "Some address"}
}

Dropwizard:"error processing your request" for retriving data from database

When i tries to open
http://localhost:8080/tailor/orders
which should return all the orders in database.but it's generating error
{"message":"There was an error processing your request. It has been logged (ID fe49a13e76c59894)."}
I'm unable to trace the problem what's causing this.
I'm using dropwizard for restful web service and hibernate from dropwizard for sqlight database.
Class:
Resources class:
#Path("/tailor")
#Produces(MediaType.APPLICATION_JSON)
public class TailorResource {
OrderDAO orderdao;
public TailorResource(OrderDAO odao) {
this.orderdao = odao;
}
#GET
#Path("/orders")
#Produces(MediaType.APPLICATION_JSON)
public List<OrderModel> getAllOrders() {
return orderdao.findAll();
}
#GET
#Path("/orders/{id}")
#Produces(MediaType.APPLICATION_JSON)
public OrderModel getOrderById(#PathParam("id") int id) {
return orderdao.findById(id);
}
}
OrderDAO class:
public class OrderDAO extends AbstractDAO<OrderModel>{
public OrderDAO(SessionFactory sessionFactory) {
super(sessionFactory);
}
public OrderModel findById(int id) {
return get(id);
}
public OrderModel create(OrderModel o) {
return persist(o);
}
public List<OrderModel> findAll() {
return list(namedQuery("com.yammer.dropwizard.tailor.model.OrderModel.findAll"));
}}
Order Class:
#NamedQueries({
#NamedQuery(
name = "com.yammer.dropwizard.tailor.model.OrderModel.findAll",
query = "SELECT o FROM OrderModel o"
),
#NamedQuery(
name = "com.yammer.dropwizard.tailor.model.OrderModel.findById",
query = "SELECT o FROM OrderModel o WHERE o.ID = :ID"
)
})
#Entity
#Table(name = "Order")
public class OrderModel {
#Id
#GeneratedValue
#Column(name = "o_id")
int ID;
#Column(name = "o_shirt_quantity")
int shirtQuantity;
#Column(name = "o_longshirt_quantity")
int longshirtQuantity;
#Column(name = "o_trouser_quantity")
int trouserQuantity;
#Column(name = "o_coat_quantity")
int coatQuantity;
#Column(name = "o_deliverydate")
Date deliveryDate;
#Column(name = "o_orderdate")
Date orderDate;
#Column(name = "o_shirt_price")
Double shirtPrice;
#Column(name = "o_longshirt_price")
Double longshirtPrice;
#Column(name = "o_trouser_price")
Double trouserPrice;
#Column(name = "o_coat_price")
Double coatPrice;
#Column(name = "o_totalamount")
Double totalAmount;
#Column(name = "o_discount")
Double discount;
#Column(name = "o_advancedpayment")
Double advancedPayment;
#Column(name = "o_remainingpayment")
Double remainingPayment;
#Column(name = "o_orderstatus")
int orderStatus;
}
Database configuration class:
public class databaseConfiguration extends Configuration {
#Valid
#NotNull
#JsonProperty
DataSourceFactory dbconfigurations = new DataSourceFactory();
public DataSourceFactory getDataSourceFactory() {
//return dbconfigurations;
Map<String,String> s=new HashMap<String,String>();
s.put("hibernate.dialect","Hibernate.SQLightDialect.SQLiteDialect");
dbconfigurations.setProperties(s);
return dbconfigurations;
}
}
Main service Class:
public class TailorApplication extends Application<databaseConfiguration> {
public static void main(String[] args) throws Exception {
new TailorApplication().run(args);
}
private final HibernateBundle<databaseConfiguration> hibernate = new HibernateBundle<databaseConfiguration>(CustomerModel.class) {
{
#Override
public DataSourceFactory getDataSourceFactory(databaseConfiguration configuration) {
return configuration.getDataSourceFactory();
}
};
#Override
public void initialize(Bootstrap<databaseConfiguration> bootstrap) {
// TODO Auto-generated method stub
bootstrap.addBundle(hibernate);
}
#Override
public void run(databaseConfiguration configuration, Environment environment)
throws Exception {
final OrderDAO odao = new OrderDAO(hibernate.getSessionFactory());
environment.jersey().register(new TailorResource(odao));
}
}
YML file:
dbconfigurations:
# the name of your JDBC driver
driverClass: org.sqlite.JDBC
# the username
user:
# the password
password:
url: jdbc:sqlite:TailorDB.db
Help please?
Make sure you filled the application class with the entities:
private final HibernateBundle<AppConfiguration> hibernateBundle = new HibernateBundle<AppConfiguration>(
//
//
//ADD ENTITIES HERE
//
//
Person.class
,Product.class
) {
#Override
public DataSourceFactory getDataSourceFactory(
AppConfiguration configuration) {
return configuration.getDataSourceFactory();
}
};
On the face of it, looks like you have missed the #UnitOfWork annotation on getAllOrders.
Having said that, the error you have shared is the external messaging that DW provides by default. Instead you should look at your web service logs for the exact error and precise stacktrace. If you run your service in terminal with java -jar path/to/shaded.jar server my.yml you should see elaborate error on the console. Please share that so that community can help better.

JAX-WS and SOAP mapping for response

I have to implements a webservice interface and the following response SOAP message has been provided:
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body SOAP-ENC:encodingStyle="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:NS2="urn:WebserviceIntf">
<NS1:VoidPaymentResponse xmlns:NS1="urn:WebserviceIntf-Webservice">
<return href="#1"/>
</NS1:VoidPaymentResponse>
<NS2:TVoidPaymentResponse id="1" xsi:type="NS2:TVoidPaymentResponse">
<MessageCode xsi:type="xsd:string">00</MessageCode>
<MessageDescription xsi:type="xsd:string">Successful</MessageDescription>
</NS2:TVoidPaymentResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is what i have for the interface web method.
#WebMethod(operationName = "VoidPayment")
#ResponseWrapper(targetNamespace = "urn:WebserviceIntf-Webservice")
#RequestWrapper(targetNamespace = "urn:WebserviceIntf-Webservice")
public VoidPaymentDetailResponse voidPayment(
#WebParam(name = "LoginID") String loginId,
#WebParam(name = "Password") String password,
#WebParam(name = "TransactionID") String transactionId,
#WebParam(name = "Echo") String additionalInformation,
#WebParam(name = "TVoidPaymentResponse", mode = WebParam.Mode.INOUT, targetNamespace = "urn:WebserviceIntf") Holder<VoidPaymentDetail> voidPaymentDetails) {
VoidPayment vp = new VoidPayment(loginId, password, transactionId, additionalInformation);
VoidPaymentDetail vpd = voidPayment(vp);
voidPaymentDetails.value = vpd;
return new VoidPaymentDetailResponse("#" + vpd.getId());
}
When i test my web method on SOAPUI. I get the following soap message:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns3:VoidPaymentResponse xmlns:ns2="http://payapi.afrocoin.com/" xmlns:ns3="urn:WebserviceIntf-Webservice" xmlns:ns4="urn:WebserviceIntf">
<return href="#Od4dY"/>
<ns4:TVoidPaymentResponse id="Od4dY">
<MessageCode>32</MessageCode>
<MessageDescription>Login failed</MessageDescription>
</ns4:TVoidPaymentResponse>
</ns3:VoidPaymentResponse>
</soap:Body>
</soap:Envelope>
Clearly there is a difference between the two messages, and i need to comply fully with the expected response.
What annotations do i need to add to the web method to make sure that this happens.
I have spent countless hours trying to figure this out.
Additional codes:
#XmlAccessorType(XmlAccessType.FIELD)
public class VoidPaymentDetailResponse {
#XmlAttribute(name = "href")
private String paymentDetail;
public VoidPaymentDetailResponse() {
}
public VoidPaymentDetailResponse(String paymentDetail) {
this.paymentDetail = paymentDetail;
}
public String getPaymentDetail() {
return paymentDetail;
}
public void setPaymentDetail(String paymentDetail) {
this.paymentDetail = paymentDetail;
}
}
#XmlType(name = "TVoidPaymentResponse", namespace = "urn:WebserviceIntf")
#Entity
#Table(name = "VoidPaymentResponseDetails")
#XmlAccessorType(XmlAccessType.FIELD)
public class VoidPaymentDetail implements Serializable {
private static final long serialVersionUID = 19383656L;
#Id
#XmlTransient
private Long detailId = IdGenerator.generateId();
#XmlAttribute
#XmlID
#Transient
private String id = IdGenerator.generateIdentifier(5);
#XmlElement(name = "MessageCode")
private String messageCode;
#XmlElement(name = "MessageDescription")
private String messageDescription;
#XmlTransient
#OneToOne
private VoidPayment voidPaymentRequest;
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public Long getDetailId() {
return detailId;
}
public void setDetailId(Long detailId) {
this.detailId = detailId;
}
public VoidPayment getVoidPaymentRequest() {
return voidPaymentRequest;
}
public void setVoidPaymentRequest(VoidPayment voidPaymentRequest) {
this.voidPaymentRequest = voidPaymentRequest;
}
public String getMessageCode() {
return messageCode;
}
public void setMessageCode(String messageCode) {
this.messageCode = messageCode;
}
public String getMessageDescription() {
return messageDescription;
}
public void setMessageDescription(String messageDescription) {
this.messageDescription = messageDescription;
}
}
I am using the default jboss wsimport.
Thanks
As per my comment. I don't believe that you can replicate the first message. This is because it contains two separate part's in the body.
http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383533
7.1 RPC and SOAP Body
A method response is modelled as a struct.
The method response is viewed as a single struct containing an accessor for the return value and each [out] or [in/out] parameter. The first accessor is the return value followed by the parameters in the same order as in the method signature.

How to access Object.field in criteria in Hibernate

i have write the criteria for company class.
below are company class, companySearch class and criteria. But criteria list is throw exception. exception is "org.hibernate.QueryException: could not resolve property: san.san of: com.sesami.common.domain.Company". How to access Company.san.san?
Company class
public class Company extends DomainObject implements UserDetails {
private Long id;
private String companyName;
private CompanyType companyType;
private String description;
private String companyURL;
private String billToEmail;
private String hashPassword;
private SAN san;
#OneToOne(cascade = { CascadeType.ALL })
public SAN getSan() {
return san;
}
public void setSan(SAN san) {
this.san = san;
}
...
}
CompanySearch
public class CompanySearch {
private String companyName;
private String email;
private Long san;
private String gstNumber;
......
public Long getSan() {
return san;
}
public void setSan(Long san) {
this.san = san;
}
...
}
Criteria
companyCriteria = this.getSession().createCriteria(
Company.class);
if (companySearch.getSan() != null
&& !"".equals(companySearch.getSan()))
companyCriteria.add(Restrictions.eq("san.san",
companySearch.getSan()));
Integer count = ((Long) companyCriteria.setProjection(
Projections.rowCount()).uniqueResult()).intValue();
companyCriteria.setProjection(null);
companyCriteria.setResultTransformer(Criteria.ROOT_ENTITY);
companyCriteria
.setFirstResult((pager.getPage() - 1) * pager.getPageSize())
.setMaxResults(pager.getPageSize()).list();
List<Company> companies = companyCriteria.list();
PagedResultSet pr = new PagedResultSet();
pr.setPager(pager);
pr.setResultSet(companies);
pr.setRowCount(count);
return pr;
You must create a join to the San entity, using a subcriteria, or an alias:
companyCriteria.createAlias("san", "sanAlias");
companyCriteria.add(Restrictions.eq("sanAlias.san",
companySearch.getSan()));
or
companyCriteria.createCriteria("san").add(Restrictions.eq("san",
companySearch.getSan()));
This is well explained in the Hibernate reference documentation and even in the Criteria javadoc.
Note that this has absolutely nothing to do with Spring, and everything to do with Hibernate. If you searched in the Spring doc for how to do this, no wonder you didn't find anything.

Categories