Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Creating a Table and add initinial values.

Thanks guys, I'm trying to do it to have some predefined values on my system. But, I will do an instalation script to insert the values, old way, :)

2011/7/18 Tom Ware <tom.ware@xxxxxxxxxx>
As mentioned below, there is not direct way to do that in JPA, but if you are doing this for testing, many test frameworks provide some kind of a mechanism.

If you are not testing, JPA provides a set of of Events you can set up listeners to and EclipseLink provides even more.  One way you could do this is, or instance, to set up a listener to EclipseLink's postLogin event and then run some code in that event to do the prepopulation.

To use the EclipseLink-specific events, you will have to register a listener in a session customizer.  See the section on: "eclipselink.session.customizer" here:

http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Using_EclipseLink_JPA_Extensions_for_Customization_and_Optimization

Documentation about our customizers can be found here:

http://wiki.eclipse.org/Introduction_to_EclipseLink_Sessions_%28ELUG%29#Session_Customization

-Tom

cinhtau wrote:
   Leandro Costa-3 wrote:
   Hi guys, I was wondering if it's possible to add some pre-defined
   values to a table when the jpa create it. E.g: I have a entity
   class, Foo, with two fields: id, description. Let's say I would like
   to have the values 1,bar inserted. is there some way to do it into
   the entity class or onther place automaticly.

Not directly in the entity class IMHO.

You can create a JUnit Testcase, that creates the corresponding entity with your properties and persist ist. Depending on your persistence unit running in container or non-container mode you have to create your entity manager. An example code for non-container mode. Replace punit with your name of the persistence unit.

EntityManagerFactory factory = Persistence.createEntityManagerFactory("punit");
EntityManager em = factory.createEntityManager();

Foo foo = new Foo();
foo.setId(1);
foo.setDescription("bar");

em.persist(foo);


------------------------------------------------------------------------
View this message in context: Re: Creating a Table and add initinial values. <http://old.nabble.com/Creating-a-Table-and-add-initinial-values.-tp32075821p32077633.html>
Sent from the EclipseLink - Users mailing list archive <http://old.nabble.com/EclipseLink---Users-f26658.html> at Nabble.com.


------------------------------------------------------------------------

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



--
http://www.leandrocosta.pro.br
- Arch Linux User - Linux User: #470599.   LPI ID: LPI000187143
- Desenvolvedor Java/Python/Web
- +55 (88) 9243-  +55 (88) 9296-4030
- Administrador de Rede ( http://www.bitwave.com.br )
- Cursando SI na Estácio ( http://www.estacio.br/ )
- Irc: lokidarkeden at freenode.com


Back to the top