Olá Pessoal,
Estou tendo alguns problemas com JPA, está dando um erro que infelizmente não consegui resolver, se alguém puder dar uma força:
package net.fratech.frasys.domain;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@SuppressWarnings("serial")
@Entity
@Table(schema="frasys")
public class Project implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
private String description;
private Date lastDate;
private String location;
@OneToMany (mappedBy = "project", cascade = CascadeType.ALL, fetch = FetchType.EAGER )
private List<Iteration> iterations;
}
package net.fratech.frasys.domain.repositories;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;
import net.fratech.frasys.domain.Project;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestProjectRepository {
private static ProjectRepository reposytory;
private static ApplicationContext ctx;
@BeforeClass
public static void prepare() throws Exception {
ctx = new ClassPathXmlApplicationContext(new String []{"applicationContext.xml", "testDomainContext.xml"});
reposytory = (ProjectRepository) ctx.getBean("projectRepository");
}
@AfterClass
public static void reset() throws Exception {
EntityManager em = Persistence.createEntityManagerFactory("frasys").createEntityManager();
em.getTransaction().begin();
Query query = em.createNativeQuery("ALTER TABLE SEQUENCE frasys.hibernate_sequence RESTART WITH 1");
query.executeUpdate();
em.createNativeQuery("DELETE FROM frasys.project").executeUpdate();
em.getTransaction().commit();
em.close();
}
private Project getProject() {
return (Project) ctx.getBean("projectExample");
}
@Test
public void testBehavior() {
Project p = testSaveNew();
}
private Project testSaveNew() {
Project p = getProject();
p.setId(13);
p = reposytory.save(p);
assertNotNull(p);
assertEquals(1,p.getId());
return p;
}
}