background preloader

A Developer's ScrapPad

Facebook Twitter

EJB3 JPA: Dealing with Date, Time and Timestamp. Today, I feel the urge to document this. Yes, even though there had been ways which databases and Java JDBC driver/Persistent engines deal with Date, Time, DateTime, Calendar, Timestamp and whatever database data type or Java class types that represent dates and time and even time zone had long been there since the very beginning, but still many developers are often confused with how to persist fields that represents date, time, date-time or timestamp through EJB3/JPA.

So, this article is mainly about 3 very simple ways that we could achieve this. I have to first admit that I am no expert in the scientific facts of representation of dates and time in the java.util.Date or java.util.Calendar class. But I do believe that by simply being able to understand a few characteristics of all these date and time related data types, whether if it is database specific or in terms of Java class types, it could definitely help you to develop applications/systems that are correct and accurate. Summary.

EJB3 JPA Entity One-To-One Relationship. A One-To-One Entity relationship is where by one entity relates to another and vice-versa. An appropriate example to illustrate this is by taking the way User information is represented. Most of the time, user information consist of Username and Password for logging into the system and it consists of user profile details such as First Name, Last Name, Addresses, Registration Date and other user relevant details. However, all the other user details besides username and password may or may not be access every time when the user logs into the system. Therefore, in terms of database structure representation, we could split them into 2 tables. Best Priced Coffee Bean Supplies For Home and Office! The below is a very simple table which illustrate the models.

And the below is a simple table creation script for MySQL as an example. Now, let’s take a look at the Java entity classes that models this structure. Package com.developerscrappad.usrmng.entity ; import java.io.Serializable ; @ Entity @Id. How To Boot MySQL 5.5 On Solaris 10 During System Startup. In this article, I’ll show you how to boot-start MySQL5.5 as part of the Service Management Facility (SMF) in Solaris 10. This is especially useful when you need the MySQL database to be started the moment when Solaris 10 boots up and running. The SMF in Solaris 10 is like other service management features in other OS like Linux and Windows whereby it manages what services (may it be server apps or other service apps) to be started or stopped in the background during system boot and runtime. Anyway, we are not going to discuss SMF here. Assumption If you have followed my posting on Installing MySQL 5.5 on Solaris 10, you should have gotten MySQL installed in the base directory (<basedir>) of “/opt/mysql/mysql” and the data directory (<datadir>) to be “/opt/mysql/mysql/data“.

Procedure Another file that you need is the MySQL database configuration file “my.cnf”. Do this as the “root” user in the terminal: Change the directory to <basedir>/support-files. <? Checking on the MySQL service. Installing MySQL 5.5 on Solaris 10. This is a little update on the past article on “Installing MySQL 5 on Solaris 10″ which was written back in August 2006 to reflect the current way of installing the MySQL version 5.5.x on Solaris 10 8/11 (u10-ga2) Again, what motivates me to write this is that it was difficult for me find a comprehensive and workable “one paged” tutorial of doing this. After spending much time on the internet looking for clues and finally making the MySQL installation a success, I’ve decided to glue and share these pieces of information with others as well. Assumption Downloads Please obtain a copy of the latest MySQL 5.5 from Preparation Please perform the following as the root user.

Installation Follow these steps to perform the installation (perform as “root“): Create the mysql group by typing “groupadd mysql“.Create the mysql user by typing “useradd -g mysql mysql“.Change the directory where the MySQL packages were placed. Initializing the Database Connecting to MySQL. Installing MySQL 5.0 on Solaris 10. This article was posted back in August 2006 in one of my first blog found on instmysql5sol10.blogspot.com. I had just shifted it here to consolidate all tutorials that I have written so far. Hopefully, it could potentially help others who had gone through some of the common obstacles and blockers of installing MySQL 5.0 on Solaris 10.

What motivates me to write this is that it was difficult for me find a comprehensive and workable “one paged” tutorial of doing this. After spending much time on the internet looking for clues and finally making the MySQL installation a success, I’ve decided to glue and share these pieces of information with others as well. Assumption Downloads Please obtain a copy of MySQL 5.0 from Preparation Please perform the following as the root user.

Installation Follow these steps to perform the installation (perform as “root“): Initializing the Database Connecting to MySQL Related Articles. EJB3 JPA Entity Many-To-Many Relationship. A Many-To-Many relationship is where by multiple object(s) are related other multiple object(s) and vice-versa. The simplest way to illustrate this is through a directory system where user(s) are related to one or many other group(s) and each group consists of multiple user(s) which belongs to. For example, user “Albert” belongs to the “Employee” group and at the same time belongs to the “Business Development” group. On the other hand, user “Rick” is one of the shareholders but actively participating in the business development aspect of the company, he belongs to the “Shareholder” group and the “Business Development”, with the same group as user “Albert”.

In fact, comparing to other relationships like One-To-One, One-To-Many and Many-To-One, a Many-To-Many relationship is a little in forming it. Most relationships require two tables + foreign keys to form. The below are the table diagram of the above example data model and the SQL codes to generate the tables in MySQL. Related Articles. EJB3 JPA Entity Many-To-One Relationship. A Many-To-One relationship is whereby one object class is “part of” or being consisted in many other object classes. Where can you discover many-To-One relationship?

Usually it appears the moment when you perform a website registration whereby you have to select your country details from a drop down box when the website ask for your profile and address details, this is when many user records shares the same record of country and states. Best Priced Coffee Bean Supplies For Home and Office! Today, let us take a look at how to store property information in the real industry. Regardless of whatever property the real estate firm sells, properties will still be categorized as apartments, condominiums, link houses, bungalows, land, SOHO, etc. Therefore, every property info will consists of a singular property type. The below are the database table diagram and the SQL codes to generate the table structure in MySQL. INSERT INTO APP_PROPERTY_TYPES ( PROPERTY_TYPE ) VALUES ( 'Apartment' ) ; @ Entity. EJB3 JPA Entity One-To-Many Relationship. A One-To-Many relationship exists when an object consists of many other related objects.

A quick way to illustrate this relationship is by taking the example of a user activity log module in a system. Every time when the user logs into the system and performs multiple tasks on it, the system will record all activities done by the specific user. In short, a user has multiple activity log records, thus the name One-To-Many. Best Priced Coffee Bean Supplies For Home and Office! The below are the table diagram and the SQL codes for generating the table in MySQL: The table stores records of users (with just the username and password for simplicity), whereas the table will store the activities that the user had performed on the system. I had encapsulated both tables into their respective Java classes. deals with table and deals with table . Package com.developerscrappad.usrmng.entity ; import java.io.Serializable ; import java.util.Set ; import javax.persistence.Column ; @ Entity @Id @ Override.

EJB3.x in Glassfish: 3 Ways to Access Local Stateless Session Bean from EJB, JSP and Servlet. Glassfish is one app server where by accessing Local Stateless Session Bean is a somewhat “confusing” as compared to other App Servers. This post will show you 3 quick, easy, straight forward, no fussed and no debates different ways that you could access your Local Session Beans to get the job done.

Yes, only Local Session Beans, NOT Remote Session Beans. Best Priced Coffee Bean Supplies For Home and Office! Way No. 1: Accessing Local Stateless Session Bean in another Session Bean Let say we have 2 session bean, SessionFacade1 and SessionFacade2 as well as their respective interfaces shows in the codes below: package com.developerscrappad.demo.intf ; import javax.ejb.Local ; @Local public interface ISessionFacade1Local public double generateRandomNumberStr ( ) ; package com.developerscrappad.demo.ejb ; import com.developerscrappad.demo.intf.ISessionFacade1Local ; import javax.ejb.Stateless ; @Stateless public class SessionFacade1 implements ISessionFacade1Local @ Override return Math . random ( ) ;

» EJB3.x JPA: How To Store An Image Or A Binary File As BLOB In Database – A Developer’s ScrapPad. In this article, we will explore how to store any simple file in database through EJB3 JPA and how to code the property field and the proper annotation type in the entity class. Database Table and Mapping the Entity By creating a simple table in MySQL to illustrate this example, the below shows the table structure of the FILE_STORAGE table. In order to store the file in the database (whether it’s an image file or a binary file), I shall define the column CONTENT with LONGBLOB data type in MySQL for the file storage.

As for the entity class, I’ll map the property data type of the CONTENT column field in the database as arrays of bytes, which is the most common way of representing binary/image file content. For BLOB-liked database data type, just mark the property field with an additional @Lob annotation. @Lob @Column( name = "CONTENT" ) private byte[] content; The full codes for FileStorageEntity.java should look like this: File Upload from JSP -> Servlet -> Session Facade -> Database ... How To Install Oracle 11g Database R2 on Solaris 10 Through SSH and VNC. Quite too often when developers are to setup a development, test or even the production environment of Oracle database running on Solaris 10 (mostly for the first time), too much hurdles and bumpers are there to cause somebody to give up too easily.

I’ve been through these tough bumpy roads too, especially when it comes to adding the proper user and groups, dealing with $DISPLAY export (just to get the installer’s UI up), changing of Kernel parameters when Oracle DB REQUIRES it, sizing of swap space if the installer yells at you and whatever the Oracle installer requires. It has always been in my heart for a very long time to write this “one page” installation guide as to aid people who are doing this installation process so that their journey could be short, sweet and less bumpy. Best Priced Coffee Bean Supplies For Home and Office! Assumption Readers are assumed to have at least some basic Unix/Linux administrative skills. Knowledge of using editors like VI. Let’s Begin Preperation: dev #! How To Boot Oracle 11g Database On Solaris 10 During System Startup Through SMF. You are here: Home » Database » Oracle » How To Boot Oracle 11g Database On Solaris 10 During System Startup Through SMF In the previous article “How To Install Oracle 11g Database R2 on Solaris 10 Through SSH and VNC“, I have mentioned that I’ll provide the instruction to start the Oracle Database during system boot.

So, this post is all about the simple nuts and bolts in how you can achieve starting the Oracle DB during boot time on Solaris 10 through SMF. Assumptions I will go through this tutorial by using a version of Oracle 11g R2 Database which had already been installed on my Solaris 10 x86-64 system. The DB was installed at the path /u01/app/oracle.I would assume that all the necessary user groups like “dba“, “oper“, “oinstall” and the user “oracle” were already created and you could smoothly start the Oracle DB through the “dbstart” command.I’ll be going through this tutorial independent from any environment variables that you’ve already defined for the “oracle” user. Summary.

EJB3 JPA: 3 Ways Of Generating Primary Key Through @GeneratedValue. Let’s face it, different Databases have different ways of generating primary key values, either in the form of identity or through a sequence generator, if the primary key field is of a numerical data type. While coding Entity classes, it is necessary to define whether the primary key value (if is it of numerical type) could be generated from the sequence generator, self generated and inserted in the database during persistent or just self define. There are also times whereby your application would rather depend on a custom created table in the DB just to store generated sequential numbers as primary keys for the Entity.

So, in this article, we’ll explore 3 ways in dealing with generating primary key values with the databases that support it and how to use the @GeneratedValue annotation effectively. Best Priced Coffee Bean Supplies For Home and Office! No. 1: GenerationType.IDENTITY To map this in the Entity class, just define the attribute in the annotation as as shown in the below: @Id. EJB 3.x JPA: Bean-Managed Transaction with javax.ejb.UserTransaction. There are times when handling of data transaction requires a little craftiness where transaction begins, commits and rollbacks could not be a straight-forward one. This is the time when Bean-Managed Transaction comes to play for business process that requires some lengthy customized units of transaction.

Best Priced Coffee Bean Supplies For Home and Office! Today, I gonna write an article/tutorial on leveraging Bean-Managed transaction through the Java EE or JEE way for the benifit of myself (yes, I am pretty forgetful and I need to keep notes for back reference) and for those who are new in programming JPA in Java EE. I won’t touch on the basics of Database ACID Transaction , Two-Phase Commit Protocol or any other technicalities of that sort.

You can always spend sometime reading these from other sites. How to Perform a Bean-Managed Transaction In the Java EE context, you can have custom defined transactions in either the Stateless Session Bean or the Stateful Session Bean. Table Name @Id. » EJB3.x JPA: When to use rollback() and setRollbackOnly() – A Developer’s Scrappad. After JTA was introduced for more than a decade ago, then later with the introduction of Bean-Managed Transaction and Container-Managed Transaction in the J2EE 1.2 specs; still, there are many developers, especially those whom had just gotten their feets wet in the marvelous world of Java EE programming were confused when to and not to use the rollback() and the setRollbackOnly() method in the UserTransaction or the EJBContext class.

Perhaps you may be coding fine grind transactional methods and have no idea why expections are all over the place and the rollback() or setRollbackOnly() just doesn’t seem to perform according to your expectation. You might think that both methods are the same (but its not). Is this the reason why you have landed on this page through google or through other web sources trying to shade some light? Rollback() and setRollbackOnly() in Bean-Managed Transaction When to use rollback() in Bean-Managed Transaction? This is a very simple and straight forward example. Making sense of EJB3.x Transaction Attributes – Part 4 (NEVER) Quick Fix: How to Solve “Unable to read the logging configuration” on Netbeans7 with JBoss6.

Making sense of EJB3.x Transaction Attributes – Part 1 (REQUIRES_NEW) – A Developer’s Scrappad | A Developer's Scrappad. Making sense of EJB3.x Transaction Attributes – Part 2 (MANDATORY) – A Developer’s Scrappad | A Developer's Scrappad. Making sense of EJB3.x Transaction Attributes – Part 3 (Difference Between SUPPORTS and NOT_SUPPORTED) MySQL Cluster NDB 7.2 on Solaris 10 Part 1 – How To Install, Setup and Configure. MySQL Cluster NDB 7.2 on Solaris 10 Part 2 – Starting, Distributed Synchronized Users Management And Stopping The Cluster. » Welcome to A Developer’s ScrapPad.