?
Solved

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

Posted on 2011-09-06
5
Medium Priority
?
541 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

649 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