Switch to full style
Java persistent API
Post a reply

System.currentTimeMillis as Id

Sat Apr 17, 2010 8:24 pm

The following example show you how to using System.currentTimeMillis() Java function to assign unique value to entity key which in following class is ( Long id ) .
Code:

package com
.codemiles.jpa;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;


@
Entity
@Table(name="TOPIC")
public class 
topic {
    @
Id
    
private long Id=System.currentTimeMillis();
    private 
String title;
    private 
Date creationDate;
    private 
Date modifedDate;
    private 
String content;
    

    public 
long getId() {
        return 
Id;
    }
    public 
void setId(long id) {
        
Id id;
    }
    
    @
Column(name="TITLE")
    public 
String getTitle() {
        return 
title;
    }
    public 
void setTitle(String title) {
        
this.title title;
    }
    
    @
Column(name="CREATION_DATE")
    public 
Date getCreationDate() {
        return 
creationDate;
    }
    public 
void setCreationDate(Date creationDate) {
        
this.creationDate creationDate;
    }
    
    @
Column(name="MODIFED_DATE")
    public 
Date getModifedDate() {
        return 
modifedDate;
    }
    public 
void setModifedDate(Date modifedDate) {
        
this.modifedDate modifedDate;
    }
    
    @
Column(name="CONTENT")
    public 
String getContent() {
        return 
content;
    }
    public 
void setContent(String content) {
        
this.content content;
    }
}
 




Post a reply
  Related Posts  to : System.currentTimeMillis as Id
 The operating system using PHP     -  
 Write to system log     -  
 Own an antivirus system in C#     -  
 Solar System - Transformations     -  
 Execute System Commands     -  
 a quematic system of a bank     -  
 mail system in java     -  
 current system time     -  
 Number system converter (C++)     -  
 best way to implement a system of name servers     -  

Topic Tags

Java JPA