[JBoss Seam] - Re: Problem testing seam using EntityManager
by margonz
I had the same problem and fixed it by copying exactly how the dvdstore ProductUnitTest gets a handle on the EntityManager. Here is what my simple test UnitTest looked like:
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.jboss.seam.mock.SeamTest;
import org.testng.annotations.Configuration;
import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceException;
import org.jboss.seam.mock.SeamTest;
import org.testng.annotations.Test;
public class UnitTest extends SeamTest {
EntityManager em() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("dvdDatabase");
EntityManager em = emf.createEntityManager();
assertNotNull("entity manager", em);
assertTrue("entity manager open", em.isOpen());
return em;
}
@Test
public void testRegisterAction() throws Exception
{
EntityManager em = em();
System.out.println("em = "+em);
em.close();
}
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4028473#4028473
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4028473
19Â years, 1Â month
[Persistence, JBoss/CMP, Hibernate, Database] - Can not run sampel with ORACLE Strange Exception
by stefan.langï¼ amigon.de
I get the following exeption on server side
17:31:21,064 INFO [STDOUT] Hibernate: select car_sequence.nextval from dual
17:31:21,070 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: com.jbossatwork.common.CarDTO, setter method of property: id
17:31:21,070 ERROR [BasicPropertyAccessor] expected type: int, actual value: java.lang.Integer
ORACLE is:
CREATE TABLE CAR
(
ID NUMBER,
MAKE VARCHAR2(50 BYTE),
MODEL VARCHAR2(50 BYTE),
MODEL_YEAR VARCHAR2(50 BYTE)
)
CAR_SEQUENCE
Code is (from JBossAtWork Book)
public class CarDTO
{
private int id;
private String make;
private String model;
private String modelYear;
public CarDTO()
{
this.id = -1;
this.make = "";
this.model = "";
this.modelYear = "";
}
public CarDTO(String make, String model, String modelYear)
{
this.id = -1;
this.make = make;
this.model = model;
this.modelYear = modelYear;
}
public CarDTO( int id, String make, String model, String modelYear)
{
this.id = id;
this.make = make;
this.model = model;
this.modelYear = modelYear;
}
/**
* @hibernate.id
* generator-class="sequence"
* column="ID"
*/
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
/**
* @hibernate.property
* column="MAKE"
*/
public String getMake()
{
return make;
}
public void setMake(String make)
{
this.make = make;
}
/**
* @hibernate.property
* column="MODEL"
*/
public String getModel()
{
return model;
}
public void setModel(String model)
{
this.model = model;
}
/**
* @hibernate.property
* column="MODEL_YEAR"
*/
public String getModelYear()
{
return modelYear;
}
public void setModelYear(String modelYear)
{
this.modelYear = modelYear;
}
}
hibernate mapping is:
<hibernate-mapping>
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-CarDTO.xml
containing the additional parameters and place it in your merge dir.
-->
car_sequence
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-CarDTO.xml
containing the additional properties and place it in your merge dir.
-->
</hibernate-mapping>
Code snipet to call hibernate on JBoss is:
session = ServiceLocator.getHibernateSession (HIBERNATE_SESSION_FACTORY);
tx = session.beginTransaction();
session.save(car);
tx.commit();
The total original code of the book is in addition not working. Here the tyep of ID was in the HBM just "int". Hibernate handbook had as type onyl "integer".
Jboss is 4.0.5 on HP-UX PA-RISK
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4028457#4028457
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4028457
19Â years, 1Â month