Código:
El metodo insert funciona bien , lo dejo para que miren aun asi try { DAOFactory daoFactory = DAOFactory.getInstance(); DAO<Cliente, Integer> userDAO = daoFactory.getDAO("Bailarinas.dao.UserDAO"); Cliente usuario = new Cliente(); System.out.println("Ingrese el nombre"); usuario.setNombres(in.next()); System.out.println("Ingrese los apellidos"); usuario.setApellidos(in.next()); System.out.println("Ingrese la cedula"); usuario.setCedula(in.next()); System.out.println("Ingrese el email"); usuario.setEmail(in.next()); System.out.println("Ingrese el telefono"); usuario.setTelefono(in.next()); //Campo de ingresos Ingreso ingreso = new Ingreso(); List<Ingreso> in = new ArrayList<Ingreso>(); ingreso.setAnio(201); ingreso.setMes(0); ingreso.setDia(82); in.add(ingreso); usuario.setIngresos(in); userDAO.insert(usuario); } catch (SystemException e) { System.out.println(e.getMessage()); }
Código:
Necesito ayuda con esto:public void insert(Entidad entidad) { factory = Persistence.createEntityManagerFactory("Bailarinas"); entityManager = factory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); entityManager.persist(entidad); transaction.commit(); entityManager.close(); }
List<Ingreso> in = new ArrayList<Ingreso>();
Le puse la llave foranea a un campo de la tabla Cliente , y ese campo tiene la tabla Ingreso , el problema es que no se como o que tipo debe ser para meterlo a la lista.
El error que me bota es este (Compilador ECLIPSE):
Cita:
[EL Info]: 2011-11-01 23:29:43.551--ServerSession(13419912)--EclipseLink, version: Eclipse Persistence Services - 1.1.1.v20090430-r4097
[EL Info]: 2011-11-01 23:29:45.451--ServerSession(13419912)--file:/G:/Base%20de%20datos/workspace/Bailarinas/build/classes/-Bailarinas login successful
Exception in thread "main" javax.persistence.RollbackException: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: Bailarinas.entity.Ingreso@530cf2.
at org.eclipse.persistence.internal.jpa.transaction.E ntityTransactionImpl.commitInternal(EntityTransact ionImpl.java:102)
at org.eclipse.persistence.internal.jpa.transaction.E ntityTransactionImpl.commit(EntityTransactionImpl. java:63)
at Bailarinas.dao.DAO.insert(DAO.java:23)
at Bailarinas.test.Main.main(Main.java:53)
Caused by: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: Bailarinas.entity.Ingreso@530cf2.
at org.eclipse.persistence.internal.sessions.UnitOfWo rkImpl.discoverAndPersistUnregisteredNewObjects(Un itOfWorkImpl.java:4015)
at org.eclipse.persistence.mappings.CollectionMapping .cascadeDiscoverAndPersistUnregisteredNewObjects(C ollectionMapping.java:324)
at org.eclipse.persistence.internal.descriptors.Objec tBuilder.cascadeDiscoverAndPersistUnregisteredNewO bjects(ObjectBuilder.java:1511)
at org.eclipse.persistence.internal.sessions.UnitOfWo rkImpl.discoverAndPersistUnregisteredNewObjects(Un itOfWorkImpl.java:4018)
at org.eclipse.persistence.internal.sessions.Repeatab leWriteUnitOfWork.discoverUnregisteredNewObjects(R epeatableWriteUnitOfWork.java:182)
at org.eclipse.persistence.internal.sessions.UnitOfWo rkImpl.calculateChanges(UnitOfWorkImpl.java:628)
at org.eclipse.persistence.internal.sessions.UnitOfWo rkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImp l.java:1386)
at org.eclipse.persistence.internal.sessions.Repeatab leWriteUnitOfWork.commitRootUnitOfWork(RepeatableW riteUnitOfWork.java:160)
at org.eclipse.persistence.internal.sessions.UnitOfWo rkImpl.commitAndResume(UnitOfWorkImpl.java:1059)
at org.eclipse.persistence.internal.jpa.transaction.E ntityTransactionImpl.commitInternal(EntityTransact ionImpl.java:84)
... 3 more
[EL Warning]: 2011-11-01 23:29:45.955--UnitOfWork(20003078)--java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: Bailarinas.entity.Ingreso@530cf2.
PD: Si es necesario subo el proyecto y gracias por adelantado. [EL Info]: 2011-11-01 23:29:43.551--ServerSession(13419912)--EclipseLink, version: Eclipse Persistence Services - 1.1.1.v20090430-r4097
[EL Info]: 2011-11-01 23:29:45.451--ServerSession(13419912)--file:/G:/Base%20de%20datos/workspace/Bailarinas/build/classes/-Bailarinas login successful
Exception in thread "main" javax.persistence.RollbackException: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: Bailarinas.entity.Ingreso@530cf2.
at org.eclipse.persistence.internal.jpa.transaction.E ntityTransactionImpl.commitInternal(EntityTransact ionImpl.java:102)
at org.eclipse.persistence.internal.jpa.transaction.E ntityTransactionImpl.commit(EntityTransactionImpl. java:63)
at Bailarinas.dao.DAO.insert(DAO.java:23)
at Bailarinas.test.Main.main(Main.java:53)
Caused by: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: Bailarinas.entity.Ingreso@530cf2.
at org.eclipse.persistence.internal.sessions.UnitOfWo rkImpl.discoverAndPersistUnregisteredNewObjects(Un itOfWorkImpl.java:4015)
at org.eclipse.persistence.mappings.CollectionMapping .cascadeDiscoverAndPersistUnregisteredNewObjects(C ollectionMapping.java:324)
at org.eclipse.persistence.internal.descriptors.Objec tBuilder.cascadeDiscoverAndPersistUnregisteredNewO bjects(ObjectBuilder.java:1511)
at org.eclipse.persistence.internal.sessions.UnitOfWo rkImpl.discoverAndPersistUnregisteredNewObjects(Un itOfWorkImpl.java:4018)
at org.eclipse.persistence.internal.sessions.Repeatab leWriteUnitOfWork.discoverUnregisteredNewObjects(R epeatableWriteUnitOfWork.java:182)
at org.eclipse.persistence.internal.sessions.UnitOfWo rkImpl.calculateChanges(UnitOfWorkImpl.java:628)
at org.eclipse.persistence.internal.sessions.UnitOfWo rkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImp l.java:1386)
at org.eclipse.persistence.internal.sessions.Repeatab leWriteUnitOfWork.commitRootUnitOfWork(RepeatableW riteUnitOfWork.java:160)
at org.eclipse.persistence.internal.sessions.UnitOfWo rkImpl.commitAndResume(UnitOfWorkImpl.java:1059)
at org.eclipse.persistence.internal.jpa.transaction.E ntityTransactionImpl.commitInternal(EntityTransact ionImpl.java:84)
... 3 more
[EL Warning]: 2011-11-01 23:29:45.955--UnitOfWork(20003078)--java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: Bailarinas.entity.Ingreso@530cf2.