?
Solved

Java temporal types,JDBC temporal types, Enumerated types,Serializable objects, Transient fields used in EJB

Posted on 2011-09-06
5
Medium Priority
?
532 Views
Last Modified: 2012-05-12
I would like to know Java temporal types,JDBC temporal types, Enumerated types,Serializable objects, Transient fields used in EJB. When, why, how, where we use them.Advantages, disadvantages of using them.  I was not clear on this concept. Thanks in advance
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 36492934

This is about  @Temporal from
http://en.wikibooks.org/wiki/Java_Persistence/Basic_Attributes

Temporal, Dates, Times, Timestamps and Calendars

Dates, times, and timestamps are common types both in the database and in Java, so in theory mappings these types should be simple, right? Well sometimes this is the case and just a normal Basic mapping can be used, however sometimes it becomes more complex.

Some databases do not have DATE and TIME types, only TIMESTAMP fields, however some do have separate types, and some just have DATE and TIMESTAMP. Originally in Java 1.0, Java only had a java.util.Date type, which was both a date, time and milliseconds. In Java 1.1 this was expanded to support the common database types with java.sql.Date, java.sql.Time, and java.sql.Timestamp, then to support internationalization Java created the java.util.Calendar type and virtually deprecated (almost all of the methods) the old date types (which JDBC still uses).

If you map a Java java.sql.Date type to a database DATE, this is just a basic mapping and you should not have any issues (ignore Oracle's DATE type that is/was a timestamp for now). You can also map java.sql.Time to TIME, and java.sql.Timestamp to TIMESTAMP. However if you have a java.util.Date or java.util.Calendar in Java and wish to map it to a DATE or TIME, you may need to indicate that the JPA provider perform some sort of conversion for this. In JPA the @Temporal annotation or <temporal> element is used to map this. You can indicate that just the DATE or TIME portion of the date/time value be stored to the database. You could also use Temporal to map a java.sql.Date to a TIMESTAMP field, or any other such conversion.
[edit] Example of temporal annotation

@Entity
public class Employee {
    ...
    @Basic
    @Temporal(DATE)
    private Calendar startDate;
    ...
}

[edit] Example of temporal XML

<entity name="Employee" class="org.acme.Employee" access="FIELD">
    <attributes>
        ...
        <basic name="startDate">
            <temporal>DATE</temporal>
        </basic>
    </attributes>
</entity>

0
 
LVL 7

Author Comment

by:gudii9
ID: 36589658
what are differences between java.util.Date and java.sql.Time. When do we use each of them. please advise. for me it seems using java.sql.Time is simple and straight forward. In that case when do i need to use java.util.Date or java.util.Calendar. please advise
0
 
LVL 7

Author Comment

by:gudii9
ID: 36589689
why Date is created under java.util but not under java.sql which surprises me. please advise
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36589723
raed this, I believe it has anextended response this question:
http://stackoverflow.com/questions/2305973/java-util-date-vs-java-sql-date

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36589753
Calendar, GergorianCalendar are newer classes which deal
much more cautiously with many subtle features
of operatiins with dates, espceailly those related tio TimeZones, differences between say standard time and daylight saving time, etcetc.
In my mind, these Claendars are less intuitive and more difficult to rememember - all rthe time
you need to checvk APIs
So if you are dealing with appliactionswhen time zones are some other subtle points are really crucial, you want
to use Calendar's. In practice at least with me it happend very rarely, so
dealing with Dates is usually fine
 
0

Featured Post

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question