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.

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.
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

Back to the top