Total members 9951 | Gratitudes |It is currently Sat Feb 11, 2012 9:51 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: @AttributeOverride with Inheritance
PostPosted: Mon Apr 26, 2010 11:48 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time

Following example show properties overloading.To do this you need to use @AttributeOverride annotation .Take in mind , that am using "TABLE_PER_CLASS" inheritance type here . @AttributeOverride can be used with other ways , you can find it also in JPA examples section.


Below you can find the entities:

Code:

package com
.codemiles.jpa;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
 
@Entity
@Table(name="SHAPE")
@
Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class Shape implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    @Id
    protected int id
;
    protected int scale;
    protected float rotate;
    protected String colour;
    protected String points;
    protected int numOfPoints;
    
    public Shape
(){
    id=(int)System.currentTimeMillis();
    }
    @Column(name="SHAPE_ID")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    @Column(name="SCALE")
    public int getScale() {
        return scale;
    }

    public void setScale(int scale) {
        this.scale = scale;
    }
    @Column(name="ROTATE")
    public float getRotate() {
        return rotate;
    }

    public void setRotate(float rotate) {
        this.rotate = rotate;
    }
 
    
@Column(name="POINTS")
    public String getPoints() {
        return points;
    }

    public void setPoints(String points) {
        this.points = points;
    }

    public void setColour(String colour) {
    this.colour = colour;
    }
    @Column(name="COLOUR")
    public String getColour() {
    return colour;
    }
    public void setNumOfPoints(int numOfPoints) {
    this.numOfPoints = numOfPoints;
    }
    @Column(name="NUM_POINTS")
    public int getNumOfPoints() {
    return numOfPoints;
    }
    
}

 


Circle shape :
Code:

package com
.codemiles.jpa;

import java.io.Serializable;

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

@
Entity
@Table(name="CIRCLE")
@
AttributeOverride(name="rotate", column=@Column(name="ROTATE_Circle"))
public class Circle extends Shape implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    protected float radius; 
  

    
    public Circle
(){
    super();
    numOfPoints =;
    
    
}


    public void setRadius(float radius) {
    this.radius = radius;
    }

    @Column(name="RADIUS")
    public float getRadius() {
    return radius;
    }
}

 

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 help me! inheritance  Java  Nasr  6
 single table inheritance  JPA  msi_333  0
 Inheritance in java  Java  msi_333  0
 Need Help about Inheritance  Java  Dummies In Java  1
 Inheritance in c++  C-C++  IT..STUDENT  6

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team