When you create an Entity Class in Netbeans 6.01, you have to choices:
- New –> Entity Class
- New –> Entity Class from Database
Choosing “Entity Class from Database” brings up a wizard to choose which database table you would like to map. If your Netbeans project is a Web Application, you get a list of Data Sources from which to choose. It shows all the JDBC Resources that are configured in your application server. Piece of cake. You’re good to go.
This is great if you’re setting up your data model inside your web application. However, if you are setting up your data model in a Java Application project (like in the tutorial), you get the list of Database Connections that are configured on your Netbeans Services tab under the Databases node.
Perhaps Netbeans has a easy/slick way of switching from Database Connection to Data Source mode on this wizard, but I haven’t found it yet. Here’s my workaround:
1.) Go ahead and select your Database Connection and complete the wizard
2.) Open persistence.xml in XML mode
3.) Remove the following properties from the properties tag:
<property name=”toplink.jdbc.user” value=”app”/>
<property name=”toplink.jdbc.password” value=”app”/>
<property name=”toplink.jdbc.url” value=”jdbc:derby://localhost:1527/sample”/>
<property name=”toplink.jdbc.driver” value=”org.apache.derby.jdbc.ClientDriver”/>
4.) Add the following tag after the provider tag
<non-jta-data-source>jdbc/sample</non-jta-data-source>
Then, we you drop the jar file for your JPA model into your web application, it will know to access the database through with a JNDI lookup at runtime.
2 cents from a RAJP:
cent 1
If you need to use this persistence unit (PU) in a web application, you ought to be using a data source (no question about it!). If you need to use the PU from a Java SE application as well, then set up two persistence units: 1 for the web that uses a Data Source and 1 for the SE app that uses a Database Connection. I haven’t tested this out, but it seems feasible.
cent 2
DO separate your JPA data model into a separate Netbeans Java Application project. Don’t build your model in your web application. You want a clear separation between the web tier and the persistence tier.
2 cents is about all this is worth because I’m a JPA newb.
March 20, 2008 at 9:54 pm
[...] details on this issue: David’s blog, JSF [...]
April 2, 2009 at 8:28 am
Hi Mr Burns
You’re an expert in netbeans
Can i make some question abaut netbeans?
I’m sorry i’m very new in java
Before i usualy use Visual Basic as my application developer.
Now i want try to make application using java web net beans and database mysql
How can i make frame for java web? there is any control available?
That frame is important to make a 2 side of web pages. one for menus and the other for the application form.
How can i make it?
I’am usualy use mysql procedure as my database querys.
There is any code from java web netbeans for executing stored procedure in mysql?
Thanks for your help
your information is so much mean for me