Pin It

"Online Tweeter Enterprise Application" : Creating a Persistence Unit in NetBeans - Part 2

Lets continue building "Online Tweeter Enterprise Application" in NetBeans. In this section of tutorial, you will create a Persistence Unit which will group set of related entity beans. Persistence Unit is necessary to create a database connection and it allows our entity objects to get stored in database as tables.


Creating a Persistence Unit in NetBeans - Follow steps mentioned below :

Step 1: Before creating a Persistence Unit in NetBeans, create a database named "tweeter" into MySQL.

Step 2: Install and Open MySQL Command Line Client as shown in fig below:

 
















Step 3: MySQL Command Line Client window pops up. It asks for the password, just provide the password provided by you at the time of installation of MySQL.


Step 4: Run the following query also shown in fig below:

Create database tweeter;
 






















Step 5: After creating a database into MySQL lets move further by creating a Persistence Unit in NetBeans.
Open "tweeter-ejb" project and right click Source Packages and then select New and than Other as shown in fig below:







Step 6: On clicking Other a dialog box appears by name New File. In the Categories: list select Persistence and in the File Types: select Persistence Unit as shown in fig below.






























Step 7: Click


New Persistence Unit dialog box gets open. It prompts us to provide or create or enter "Persistence Unit Name: ", "Persistence provider: ", "Data Source: ", use of Java Transaction API and Table Generation Strategy etc... provide values to it according to the fig below.









 














Step 8: Don't click Finish. Lets create New Data Source. Select New Data Source from the list as shown in fig below:

























Step 9:  On clicking New Data Source, Create Data Source dialog box gets open as shown in the fig below. Just enter JNDI name for the Data Source and select New Database Connection from the list Database Connection:




Step 10: On clicking New Database Connection, New Connection Wizard dialog box gets open. It prompts us to enter information about the Driver and Driver File. Since for this application MySQL is the database choose from the drivers list MySQL (Connector/J driver). In the Driver File just click on Add button and add the required JDBC jar for MySQL as shown in fig below.






Step 11: Click


New Connection Wizard dialog box gets open which prompts us to enter information about Driver Name, Host, Port, Database, User Name, Password. Just provide information as shown in fig. For User Name and Password enter the information you provided at the time of installing MySQL Database Server.





























Step 12: Click


and than just click 



Step 13: Previous Create Data Source dialog box gets open having information about the newly created Data Source as shown in fig.



Step 14: Click



Previous New Persistence Unit dialog box gets open with the information about the Data Source as shown in fig below.



Step 15: Click



and Persistence Unit gets created having the necessary information in the persistence.xml file created by NetBeans (shown below) and placed in the Configuration Files folder in the Tweeter-ejb module.







    
  
    org.eclipse.persistence.jpa.PersistenceProvider
    jndi/tweeter
    false
    
      
    
  





In the next section of this blog (part 3) you will learn how to create an Entity Bean class in NetBeans for this application.

Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot