is there a skeleton for a project using mysql, some eclipse/top link with RESOURCE_LOCAL as connection type? Preferably using maven. I’m searching for it for hours and can’t get running even the sipmlest exaple. So if you had it ready and running, please, post :-). Even something as simple as these two classes only.
@Entity
public class Message implements Serializable{
public Message() {}
public Message(String s){
this.s = s;
}
@Id
String s;
public String getS(){
return s;
}
}
public class App {
static private EntityManagerFactory emf;
static private EntityManager em;
public static void main( String[] args ) {
emf = Persistence.createEntityManagerFactory("persistence");
em = emf.createEntityManager();
Message m = new Message("abc");
em.persist(m);
}
}
Maven has an archetype for JPA Application that is available from the internal catalog
$ mvn archetype:generate [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Preparing archetype:generate [INFO] No goals needed for project - skipping [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. [INFO] Setting property: velocimacro.messages.on => 'false'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] Setting property: resource.manager.logwhenfound => 'false'. [INFO] [archetype:generate {execution: default-cli}] [INFO] Generating project in Interactive mode [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) Choose archetype: ... 23: internal -> jpa-maven-archetype (JPA application) ... Choose a number: (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41) 15: :Or more directly:
This will generate a nice project using Hibernate, HSQLDB with a DbUnit test. Now,
cdinto the created directory to make some changes.First of all, edit the
pom.xml. Remove the Hibernate related artifacts and replace them by EclipseLink (you’ll need an extra repository):Then modify the
persistence.xml(note that there are 2 persistence units below and the one filled is used during tests):That’s all. I’ve posted the modified
pom.xmlon pastebin.com. To use MySQL, add the JDBC driver as dependency in thepom.xmland replicate the EclipseLink configuration. This should be easy and is left as an exercise for the reader 🙂 In case of a blocking problem, leave a comment and I’ll see if I can help.If you want to make the test pass again, you’ll have to replace the following lines in
UserTest.java:By