The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 An Introduction to Java Persistence for Client-Side Developers
Subject:  Getting this working on Derby with Netbeans
Date:  2006-07-18 00:01:19
From:  rickcarson
Response to: first is an invalid name


Hi Joshua. Interesting article.

I noted that an earlier poster tried this in Derby and couldn't get first to work. I also got this working in Derby but it took a bit of jumping through hoops so I'm going to detail the steps I took in case it helps someone else. :D

But before I do - it may be worth noting that rather than changing Person.java as I and the previous poster did, the 'zen' of EE 5 is to probably change the column it maps to via the Annotation (though there is a certain elegance to letting the db pick up and run with a default column name as well...)

So here's what I did:

  1. Type in classes as per example.
  2. Fiddle the persistence.xml
  3. I put the Toplink essentials jar in my classpath.
  4. Got a strange exception.
  5. Suspected something was wrong with my persistence.xml. Moved it out of my project directory entirely.
  6. Still got same error.
  7. Read the article more carefully. Ahha! It has to go in the META-INF directory. *blushes*.
  8. Run it again, this time I get a bunch of output about how it is going to do the mapping... looking good so far... and I get a whopping big error which boils down to:

Configuration error. Class [org.apache.derby.jdbc.ClientDriver] not found.

  • Oops. Try to find this class on my system. No dice.
  • Go and download the Derby zip from the apache site. Unpack the zip and slap the jars which start with Derby (as prime suspects) on my classpath.
  • Great, we have fluffy dice.
  • Oh wait, what is this? Derby is not running? Umm... fire up Netbeans and run it through the runtime console (not sure if this is cheating).
  • Fantastic, now it complains about FIRST in the SQL statement. No problem, fix the class... and we are good to go, tables and data show up in the Netbeans inspector.

*phew*

NB: much fiddling with the persistence.xml ommitted for the sake of brevity.

For reference, here is the persistence.xml file I ended up using: (oh darn, there is no preview... this is gonna look bad) <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="sample" transaction-type="RESOURCE_LOCAL"> <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider> <class>addressbook.Person</class> <properties> <property name="toplink.jdbc.user" value="****"/> <property name="toplink.jdbc.password" value="****"/> <property name="toplink.jdbc.url" value="jdbc:derby://localhost:1527/sample"/> <property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> <property name="toplink.ddl-generation" value="create-tables"/> </properties> </persistence-unit> </persistence>


 Feed java.net RSS Feeds