Hibernate One To One引起:org.hibernate.MappingException:无法确定类型

时间:2016-04-03 04:41:59

标签: java spring hibernate

现在,我正在学习hibernate,并开始在我的项目中使用它。这是一个CRUD应用程序。我使用hibernate进行所有的crud操作。它适用于所有人。但是,一对一,我厌倦了尝试它。最后它给了我以下错误。

Caused by: org.hibernate.MappingException: Could not determine type for: org.ppbni.splatter.model.Wafat, at table: user, for columns: [org.hibernate.mapping.Column(wafatDetail)]

这是我的useradmin模型,

package org.ppbni.splatter.model;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.OneToOne;
import javax.persistence.CascadeType;

@Entity
@Table(name="user")
public class UserAdmin {

private String no_dana;
private String npp;
private String password;
private String nama_depan;
private String nama_tengah;
private String nama_belakang;
private String agama;
private String jenis_kelamin;
private Date tgl_lahir; 
private String alamat;
private String rt;
private String rw;
private String kelurahan;
private String kecamatan;
private String kota;
private String kode_pos;
private String propinsi;
private String no_telepon;
private String no_handphone_1;
private String no_handphone_2;
private String display_name;
private Date tgl_gabung;
private Date last_login;
private Integer enabled;
private String status;
private String unit_terakhir;
private String jabatan_terakhir;
private String pangkat_terakhir;
private String authority;

@Id
@GeneratedValue
@Column(name="no_dana", unique=true, nullable=false)
public String getNo_dana() {
    return no_dana;
}
public void setNo_dana(String no_dana) {
    this.no_dana = no_dana;
}
@Column(name="npp")
public String getNpp() {
    return npp;
}
public void setNpp(String npp) {
    this.npp = npp;
}
@Column(name="password")
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
@Column(name="nama_depan")
public String getNama_depan() {
    return nama_depan;
}
public void setNama_depan(String nama_depan) {
    this.nama_depan = nama_depan;
}
@Column(name="nama_tengah")
public String getNama_tengah() {
    return nama_tengah;
}
public void setNama_tengah(String nama_tengah) {
    this.nama_tengah = nama_tengah;
}
@Column(name="nama_belakang")
public String getNama_belakang() {
    return nama_belakang;
}
public void setNama_belakang(String nama_belakang) {
    this.nama_belakang = nama_belakang;
}
@Column(name="agama")
public String getAgama() {
    return agama;
}
public void setAgama(String agama) {
    this.agama = agama;
}
@Column(name="jenis_kelamin")
public String getJenis_kelamin() {
    return jenis_kelamin;
}
public void setJenis_kelamin(String jenis_kelamin) {
    this.jenis_kelamin = jenis_kelamin;
}
@Temporal(TemporalType.DATE)
@Column(name = "tgl_lahir")
public Date getTgl_lahir() {
    return tgl_lahir;
}
public void setTgl_lahir(Date tgl_lahir) {
    this.tgl_lahir = tgl_lahir;
}

@Column(name="alamat")
public String getAlamat() {
    return alamat;
}
public void setAlamat(String alamat) {
    this.alamat = alamat;
}

@Column(name="rt")
public String getRt() {
    return rt;
}
public void setRt(String rt) {
    this.rt = rt;
}
@Column(name="rw")
public String getRw() {
    return rw;
}
public void setRw(String rw) {
    this.rw = rw;
}

@Column(name="kelurahan")
public String getKelurahan() {
    return kelurahan;
}
public void setKelurahan(String kelurahan) {
    this.kelurahan = kelurahan;
}

@Column(name="kecamatan")
public String getKecamatan() {
    return kecamatan;
}
public void setKecamatan(String kecamatan) {
    this.kecamatan = kecamatan;
}

@Column(name="kota")
public String getKota() {
    return kota;
}
public void setKota(String kota) {
    this.kota = kota;
}

@Column(name="kode_pos")
public String getKode_pos() {
    return kode_pos;
}
public void setKode_pos(String kode_pos) {
    this.kode_pos = kode_pos;
}

@Column(name="propinsi")
public String getPropinsi() {
    return propinsi;
}
public void setPropinsi(String propinsi) {
    this.propinsi = propinsi;
}

@Column(name="no_telepon")
public String getNo_telepon() {
    return no_telepon;
}
public void setNo_telepon(String no_telepon) {
    this.no_telepon = no_telepon;
}
@Column(name="no_handphone_1")
public String getNo_handphone_1() {
    return no_handphone_1;
}
public void setNo_handphone_1(String no_handphone_1) {
    this.no_handphone_1 = no_handphone_1;
}

@Column(name="no_handphone_2")
public String getNo_handphone_2() {
    return no_handphone_2;
}
public void setNo_handphone_2(String no_handphone_2) {
    this.no_handphone_2 = no_handphone_2;
}

@Column(name="display_name")
public String getDisplay_name() {
    return display_name;
}
public void setDisplay_name(String display_name) {
    this.display_name = display_name;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "tgl_gabung")
public Date getTgl_gabung() {
    return tgl_gabung;
}
public void setTgl_gabung(Date tgl_gabung) {
    this.tgl_gabung = tgl_gabung;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "last_login")
public Date getLast_login() {
    return last_login;
}
public void setLast_login(Date last_login) {
    this.last_login = last_login;
}
@Column(name="enabled")
public Integer getEnabled() {
    return enabled;
}
public void setEnabled(Integer enabled) {
    this.enabled = enabled;
}
@Column(name="status")
public String getStatus() {
    return status;
}
public void setStatus(String status) {
    this.status = status;
}
@Column(name="unit_terakhir")
public String getUnit_terakhir() {
    return unit_terakhir;
}
public void setUnit_terakhir(String unit_terakhir) {
    this.unit_terakhir = unit_terakhir;
}
@Column(name="jabatan_terakhir")
public String getJabatan_terakhir() {
    return jabatan_terakhir;
}
public void setJabatan_terakhir(String jabatan_terakhir) {
    this.jabatan_terakhir = jabatan_terakhir;
}
@Column(name="pangkat_terakhir")
public String getPangkat_terakhir() {
    return pangkat_terakhir;
}
public void setPangkat_terakhir(String pangkat_terakhir) {
    this.pangkat_terakhir = pangkat_terakhir;
}
@Column(name="authority")
public String getAuthority() {
    return authority;
}
public void setAuthority(String authority) {
    this.authority = authority;
}

@OneToOne(mappedBy="useradmin", cascade=CascadeType.ALL)
private Wafat wafat;

public Wafat getWafat(){
    return wafat;
}

public void setWafat(Wafat wafat){
    this.wafat = wafat;
}

/**
 * @param args
 */

}

这是我的wafat模型,

package org.ppbni.splatter.model;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.PrimaryKeyJoinColumn;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

@Entity
@Table(name="wafat")
public class Wafat {

private String kode_wafat;
private String no_dana;
private Date tgl_wafat;
private int usia_wafat;
private Date tgl_makam;
private String tempat_makam;

@Id
@Column(name="kode_wafat", unique=true, nullable=false)
public String getKode_wafat() {
    return kode_wafat;
}
public void setKode_wafat(String kode_wafat) {
    this.kode_wafat = kode_wafat;
}
@Id
@Column(name="no_dana", unique=true, nullable=false)
@GeneratedValue(generator="gen")
@GenericGenerator(name="gen", strategy="foreign", parameters=@Parameter(name="property", value="user"))
public String getNo_dana() {
    return no_dana;
}
public void setNo_dana(String no_dana) {
    this.no_dana = no_dana;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name="tgl_wafat")
public Date getTgl_wafat() {
    return tgl_wafat;
}
public void setTgl_wafat(Date tgl_wafat) {
    this.tgl_wafat = tgl_wafat;
}
@Column(name="usia_wafat")
public int getUsia_wafat() {
    return usia_wafat;
}
public void setUsia_wafat(int usia_wafat) {
    this.usia_wafat = usia_wafat;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name="tgl_makam")
public Date getTgl_makam() {
    return tgl_makam;
}
public void setTgl_makam(Date tgl_makam) {
    this.tgl_makam = tgl_makam;
}
@Column(name="tempat_makam")
public String getTempat_makam() {
    return tempat_makam;
}
public void setTempat_makam(String tempat_makam) {
    this.tempat_makam = tempat_makam;
}

@OneToOne
@PrimaryKeyJoinColumn
private UserAdmin useradmin;

/**
 * @param args
 */

}

这是我的控制器,

@SuppressWarnings("unchecked")
@RequestMapping("/berita-duka.html")
public ModelAndView listAllWafat(ModelMap model)throws Exception{
    ModelAndView mav = new ModelAndView("beritaduka");

    SessionFactory factory = new Configuration().configure().buildSessionFactory();
    Session session = factory.openSession();

    List<UserAdmin> useradmin = session.createQuery("from UserAdmin").list();
    for (UserAdmin useradmin1 : useradmin){
        System.out.println(useradmin1.getNama_tengah() + " , "
                + useradmin1.getKota() + ", "
                + useradmin1.getWafat().getKode_wafat());
    }

    session.close();
    factory.close();

    return mav;

}

另一个例外:

SEVERE: Servlet.service() for servlet [dispatcher] in context with path    [/PPBNI] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at       org.ppbni.splatter.web.controller.GenController.listAllWafat(GenController.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

任何帮助都会很愉快:)

1 个答案:

答案 0 :(得分:2)

我认为您的映射错误,希望在OneToOneUserAdmin类之间进行Wafat映射,两者共享相同的主键。

如果是这样,您可能需要尝试使用MapsIdPrimaryKeyJoinColumn注释的以下映射。

<强> UserAdmin.java

@Entity
@Table(name="user")
class UserAdmin implements Serializable {

private int no_dana;
private String npp;
private String password;
private String nama_depan;
private String nama_tengah;
private String nama_belakang;
private String agama;
private String jenis_kelamin;
private Date tgl_lahir; 
private String alamat;
private String rt;
private String rw;
private String kelurahan;
private String kecamatan;
private String kota;
private String kode_pos;
private String propinsi;
private String no_telepon;
private String no_handphone_1;
private String no_handphone_2;
private String display_name;
private Date tgl_gabung;
private Date last_login;
private Integer enabled;
private String status;
private String unit_terakhir;
private String jabatan_terakhir;
private String pangkat_terakhir;
private String authority;

@Id
@GeneratedValue
@Column(name="no_dana", unique=true, nullable=false)
public int getNo_dana() {
    return no_dana;
}
public void setNo_dana(int no_dana) {
    this.no_dana = no_dana;
}
@Column(name="npp")
public String getNpp() {
    return npp;
}
public void setNpp(String npp) {
    this.npp = npp;
}
@Column(name="password")
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
@Column(name="nama_depan")
public String getNama_depan() {
    return nama_depan;
}
public void setNama_depan(String nama_depan) {
    this.nama_depan = nama_depan;
}
@Column(name="nama_tengah")
public String getNama_tengah() {
    return nama_tengah;
}
public void setNama_tengah(String nama_tengah) {
    this.nama_tengah = nama_tengah;
}
@Column(name="nama_belakang")
public String getNama_belakang() {
    return nama_belakang;
}
public void setNama_belakang(String nama_belakang) {
    this.nama_belakang = nama_belakang;
}
@Column(name="agama")
public String getAgama() {
    return agama;
}
public void setAgama(String agama) {
    this.agama = agama;
}
@Column(name="jenis_kelamin")
public String getJenis_kelamin() {
    return jenis_kelamin;
}
public void setJenis_kelamin(String jenis_kelamin) {
    this.jenis_kelamin = jenis_kelamin;
}
@Temporal(TemporalType.DATE)
@Column(name = "tgl_lahir")
public Date getTgl_lahir() {
    return tgl_lahir;
}
public void setTgl_lahir(Date tgl_lahir) {
    this.tgl_lahir = tgl_lahir;
}

@Column(name="alamat")
public String getAlamat() {
    return alamat;
}
public void setAlamat(String alamat) {
    this.alamat = alamat;
}

@Column(name="rt")
public String getRt() {
    return rt;
}
public void setRt(String rt) {
    this.rt = rt;
}
@Column(name="rw")
public String getRw() {
    return rw;
}
public void setRw(String rw) {
    this.rw = rw;
}

@Column(name="kelurahan")
public String getKelurahan() {
    return kelurahan;
}
public void setKelurahan(String kelurahan) {
    this.kelurahan = kelurahan;
}

@Column(name="kecamatan")
public String getKecamatan() {
    return kecamatan;
}
public void setKecamatan(String kecamatan) {
    this.kecamatan = kecamatan;
}

@Column(name="kota")
public String getKota() {
    return kota;
}
public void setKota(String kota) {
    this.kota = kota;
}

@Column(name="kode_pos")
public String getKode_pos() {
    return kode_pos;
}
public void setKode_pos(String kode_pos) {
    this.kode_pos = kode_pos;
}

@Column(name="propinsi")
public String getPropinsi() {
    return propinsi;
}
public void setPropinsi(String propinsi) {
    this.propinsi = propinsi;
}

@Column(name="no_telepon")
public String getNo_telepon() {
    return no_telepon;
}
public void setNo_telepon(String no_telepon) {
    this.no_telepon = no_telepon;
}
@Column(name="no_handphone_1")
public String getNo_handphone_1() {
    return no_handphone_1;
}
public void setNo_handphone_1(String no_handphone_1) {
    this.no_handphone_1 = no_handphone_1;
}

@Column(name="no_handphone_2")
public String getNo_handphone_2() {
    return no_handphone_2;
}
public void setNo_handphone_2(String no_handphone_2) {
    this.no_handphone_2 = no_handphone_2;
}

@Column(name="display_name")
public String getDisplay_name() {
    return display_name;
}
public void setDisplay_name(String display_name) {
    this.display_name = display_name;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "tgl_gabung")
public Date getTgl_gabung() {
    return tgl_gabung;
}
public void setTgl_gabung(Date tgl_gabung) {
    this.tgl_gabung = tgl_gabung;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "last_login")
public Date getLast_login() {
    return last_login;
}
public void setLast_login(Date last_login) {
    this.last_login = last_login;
}
@Column(name="enabled")
public Integer getEnabled() {
    return enabled;
}
public void setEnabled(Integer enabled) {
    this.enabled = enabled;
}
@Column(name="status")
public String getStatus() {
    return status;
}
public void setStatus(String status) {
    this.status = status;
}
@Column(name="unit_terakhir")
public String getUnit_terakhir() {
    return unit_terakhir;
}
public void setUnit_terakhir(String unit_terakhir) {
    this.unit_terakhir = unit_terakhir;
}
@Column(name="jabatan_terakhir")
public String getJabatan_terakhir() {
    return jabatan_terakhir;
}
public void setJabatan_terakhir(String jabatan_terakhir) {
    this.jabatan_terakhir = jabatan_terakhir;
}
@Column(name="pangkat_terakhir")
public String getPangkat_terakhir() {
    return pangkat_terakhir;
}
public void setPangkat_terakhir(String pangkat_terakhir) {
    this.pangkat_terakhir = pangkat_terakhir;
}
@Column(name="authority")
public String getAuthority() {
    return authority;
}
public void setAuthority(String authority) {
    this.authority = authority;
}

private Wafat wafat;

@OneToOne(mappedBy="useradmin", cascade=CascadeType.ALL)
@PrimaryKeyJoinColumn
public Wafat getWafat(){
    return wafat;
}

public void setWafat(Wafat wafat){
    this.wafat = wafat;
}

<强> Wafat.java

@Entity
@Table(name="wafat")
class Wafat implements Serializable{

private String kode_wafat;
private int no_dana;
private Date tgl_wafat;
private int usia_wafat;
private Date tgl_makam;
private String tempat_makam;

@Column(name="kode_wafat", unique=true, nullable=false)
public String getKode_wafat() {
    return kode_wafat;
}
public void setKode_wafat(String kode_wafat) {
    this.kode_wafat = kode_wafat;
}
@Id
@JoinColumn(name="no_dana")
public int getNo_dana() {
    return no_dana;
}
public void setNo_dana(int no_dana) {
    this.no_dana = no_dana;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name="tgl_wafat")
public Date getTgl_wafat() {
    return tgl_wafat;
}
public void setTgl_wafat(Date tgl_wafat) {
    this.tgl_wafat = tgl_wafat;
}
@Column(name="usia_wafat")
public int getUsia_wafat() {
    return usia_wafat;
}
public void setUsia_wafat(int usia_wafat) {
    this.usia_wafat = usia_wafat;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name="tgl_makam")
public Date getTgl_makam() {
    return tgl_makam;
}
public void setTgl_makam(Date tgl_makam) {
    this.tgl_makam = tgl_makam;
}
@Column(name="tempat_makam")
public String getTempat_makam() {
    return tempat_makam;
}
public void setTempat_makam(String tempat_makam) {
    this.tempat_makam = tempat_makam;
}

private UserAdmin useradmin;

@OneToOne
@MapsId
@JoinColumn(name="no_dana")
public UserAdmin getUseradmin() {
    return useradmin;
}
public void setUseradmin(UserAdmin useradmin) {
    this.useradmin = useradmin;
}

}

并保存实体:

UserAdmin ua = new UserAdmin();
Wafat w = new Wafat();
w.setKode_wafat("Kode_Wafat");
ua.setWafat(w);
w.setUseradmin(ua);
session.persist(ua);

一些建议:

  1. 您在字段和属性上混合了hibernate注释。坚持一种方法,在字段或属性上设置hibernate注释。
  2. 如果你明白自己正在学习hibernate,那么我建议先尝试使用较小的类。太多的领域,它可能会让你感到困惑。