@Entity @Table(name="kategori") public class Kategori{ @Id @Column(name="kode_kategori") private String kodeKatogori;
@Column(name="nama_kategori" private String namaKategori; @OneToMany(mappedBy="barang") private List<Barang> barangs = new ArrayList<Barang>(); //getter setter di sini } @Entity @Table(name="jenis") public class Jenis{ @Id @Column(name="kode_jenis") private String kodeJenis; @Column(name="nama_jenis" private String namaJenis; @OneToMany(mappedBy="jenis") private List<Barang> barangs = new ArrayList<Barang>(); //getter setter di sini } @Entity @Table(name="barang") public class Barang{ @Id @Column(name="kode_barang") private String kodeBarang; @Column(name="nama_barang" private String namaBarang; @ManyToOne @JoinColumn(name="kode_kategori") private Kategori kategori; @ManyToOne @JoinColumn(name="kode_jenis") private Jenis jenis; //getter setter di sini } //HIbernate config xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- SQL Dialect --> <property name="hibernate.show_sql">true</property> <!-- Mapping Table to Object --> <mapping class="model.Jenis"/> <mapping class="model.Kategori"/> <mapping class="model.Barang"/> </session-factory> </hibernate-configuration> application contex xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- Nama file tempat properties file --> <context:property-placeholder location="database.properties"/> <context:component-scan base-package="model"/> <context:annotation-config/> <tx:annotation-driven/> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="${jdbc.driver_class}" p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" p:dataSource-ref="dataSource" p:configLocation="hibernate.cfg.xml"> <property name="hibernateProperties"> <props> <prop key="dialect">${hibernate.dialect} </prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory"/> </beans> Selanjutnya : - setting web xml - bikin dao - bikin service -- Senior Engineer @ ArtiVisi Intermedia Java Training Center See our course @ artivisi.com http://ifnu.artivisi.com +62 856 9211 8687 regards