Using hibernate with embedded derby?

I use Apache Derby with bernate for testing one of my project's model classes (their equals hashCode implementations, queries, etc. ). MySQL is used as the production database. I choose Derby instead of HSQLDB because I've experienced some incompatibilities with meaning, given my entities (their name, schema, keys) and their relation bernate couldn't create my database schema in HSQLDB, while it could with Derby.

That said, maybe I messed up something; also the incompatibilities could have been resolved.

I use Apache Derby with bernate for testing one of my project's model classes (their equals, hashCode implementations, queries, etc. ). MySQL is used as the production database. I choose Derby instead of HSQLDB, because I've experienced some incompatibilities with meaning, given my entities (their name, schema, keys) and their relation bernate couldn't create my database schema in HSQLDB, while it could with Derby.

That said, maybe I messed up something; also the incompatibilities could have been resolved. Anyway, here is what I use in my tests (I've modified my pom. Xml so that it would include Derby as a runtime dependency and run a single test, just to make sure it's working).

Pom. Xml ... org. Hibernate hibernate-entitymanager 3.6.8.

Final org.apache. Derby derby 10.8.2.2 runtime org. Slf4j slf4j-simple 1.6.4 runtime ... persistence.

Xml org.hibernate.ejb. BernatePersistence Test Test entity @Entity @Table(name = "test") public class Test { @Id public int id; @Basic public String data; } Test EntityManagerFactory emf = Persistence. CreateEntityManagerFactory("test"); EntityManager em = emf.

CreateEntityManager(); EntityTransaction tx = em.getTransaction(); Test test = em. Find(Test. Class, 1); if (test == null) { test = new Test(); test.Id = 1; test.

Data = "a"; tx.begin(); em. Persist(test); tx.commit(); } System.out. Format("Test{id=%s, data=%s}\n", test.

Id, test. Data); em.close(); emf.close().

– Msaleh Dec 11 '11 at 11:41 1 @Msaleh If you use a JDBC URL like jdbc:derby:test;create=true a database will be created on your first connect. If you use the then bernate will create the tables necessary to hold your entities. The generated schema's name, table names, etc. All can be controlled through standard Java annotations.

However I advise you to create your database and tables by hand and don't rely on bernate to create a good schema for you. You can interface with Apache derby with ij which is like mysql for MySQL to manage databases and such. – Kohányi Róbert Dec 11 '11 at 12:36 how to create the derby embedded database by hand?

– Msaleh Dec 11 '11 at 13:07 1 @Msaleh Use ij, which is like mysql (the client command-line interface tool) to MySQL.It has an extensive documentation. Basically, you start ij and connect to a database: ij> connect 'jdbc:derby:/database;create=true';. Create=true tells ij to create the database if doesn't exist.

From there on you do what you want, create tables, drop them, query them or whatever. I advise you to refer to the documentation if you're unsure about something, because it is well written and extensive. – Kohányi Róbert Dec 11 '11 at 14:01 thanks a lot for such great answer, please update the answer with what we discussed in the comments.

– Msaleh Dec 11 '11 at 14:22.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions