The people that use the cafeto-entitycopy utility can be use the follow maven dependency.
<dependecy> <groupId>net.cafeto.entitycopy</groupId> <artifactId>cafeto-entitycopy</artifactId> <version>5.0.3</version> <dependency>
This blog is for the project "cafeto.net".
<dependecy> <groupId>net.cafeto.entitycopy</groupId> <artifactId>cafeto-entitycopy</artifactId> <version>5.0.3</version> <dependency>
@Entity
public class Address {
@Id
String id;
String street;
...
}
@Entity
public class Person {
@Id
String id;
String firstName;
String lastName;
@ManyToOne // By default FetchType.EAGER
Person parent;
@OneToMany // By default FetchType.LAZY
Set<Address> addresses = new HashTable<Address>();
..
}
Person entity = personDao.findByPk(pk); ... Person copy = EntityCopy.copy(Person entity, DeepCopy.DEFAULT);
DeepCopy deepCopy = DeepCopy.createFull().add("addresses", DeepCopy.createNone());
Person copy = EntityCopy.copy(entity, deepCopy);@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public interface TestServiceSEI {
@WebMethod
public List<Person> findAllPersons(@javax.jws.WebParam(name="deepCopy") DeepCopy deepCopy);
}
@Stateless
@WebService(endpointInterface="TestServiceSEI")
@Remote(TestServiceSEI.class)
public class TestServiceBean implements TestServiceSEI {
@javax.persistence.PersistenceContext(unitName = "TestPU")
protected javax.persistence.EntityManager entityManager;
@javax.annotation.Resource
protected javax.xml.ws.WebServiceContext wsCtx;
public List<Person> findAllPersons(DeepCopy deepCopy) {
Query query = this.getEntityManager().createQuery("select obj from Person obj");
List<Person> entities = query.getResultList();
if (wsCtx != null) {
List<Person> results = new ArrayList<Person>();
for (Person entity : entities) {
results.add(EntityCopy.copy(entity, deepCopy));
}
return results;
}
return entities;
}
}
<?php
require_once "Cafeto/DeepCopy.php";
class TestService {
protected $soapClient;
public function __construct($wsdl) {
$this->soapClient = new SoapClient($wsdl);
}
public function findAllPersons($deepCopy) {
$ret = $this->soapClient->findAllPersons(array('deepCopy' => $deepCopy));
if (isset($ret->return))
if (is_array($ret->return))
return $ret->return;
else
return array($ret->return);
else
return array();
}
}
$service = new TestService("http://127.0.0.1:8080/test-service/TestService?wsdl");
$deepCopy = Cafeto_DeepCopy::createFull()->add("addresses", Cafeto_DeepCopy::createNone());
$persons = $service->findAllPersons($deepCopy);
$ git clone git://github.com/cafeto/cafeto-entitycopy