Created
January 19, 2014 21:41
-
-
Save sercanyanaz/8511336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.object; | |
import javax.persistence.DiscriminatorColumn; | |
import javax.persistence.DiscriminatorType; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
import javax.persistence.Inheritance; | |
import javax.persistence.InheritanceType; | |
@Entity | |
@Inheritance(strategy=InheritanceType.JOINED) | |
//@DiscriminatorColumn(name="AracTipi",discriminatorType=DiscriminatorType.STRING) | |
public class Arac { | |
@Id @GeneratedValue(strategy=GenerationType.TABLE) | |
private int id; | |
private String marka; | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getMarka() { | |
return marka; | |
} | |
public void setMarka(String marka) { | |
this.marka = marka; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.object; | |
import javax.persistence.DiscriminatorValue; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
@Entity | |
//@DiscriminatorValue(value="Kamyon") | |
public class Kamyon extends Arac { | |
private int boy; | |
public int getBoy() { | |
return boy; | |
} | |
public void setBoy(int boy) { | |
this.boy = boy; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.object; | |
import javax.persistence.DiscriminatorValue; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
@Entity | |
//@DiscriminatorValue(value="Taksi") | |
public class Taksi extends Arac { | |
private String color; | |
public String getColor() { | |
return color; | |
} | |
public void setColor(String color) { | |
this.color = color; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.object; | |
import org.hibernate.Session; | |
import org.hibernate.SessionFactory; | |
import org.hibernate.cfg.AnnotationConfiguration; | |
import org.hibernate.tool.hbm2ddl.SchemaExport; | |
public class Test { | |
public static void main(String[] args) { | |
AnnotationConfiguration config = new AnnotationConfiguration(); | |
config.addAnnotatedClass(Taksi.class); | |
config.addAnnotatedClass(Kamyon.class); | |
config.addAnnotatedClass(Arac.class); | |
config.configure("hibernate.cfg.xml"); | |
// new SchemaExport(config).create(true, true); | |
SessionFactory fac = config.buildSessionFactory(); | |
Session ses = fac.openSession(); | |
ses.beginTransaction(); | |
Arac a = new Arac(); | |
Taksi t = new Taksi(); | |
t.setColor("mavi"); | |
Kamyon k = new Kamyon(); | |
k.setBoy(10); | |
ses.save(a); | |
ses.save(k); | |
ses.save(t); | |
ses.getTransaction().commit(); | |
ses.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment