i have 4 tables kode_pos, korwil, user, and wafat. in Korwil class, it hold foreign key from user and give the primary key to kode_pos, which mean there are 2 mapping in korwil class @OneToOne and @OneToMany,
I got this error
org.hibernate.AnnotationException: Unknown mappedBy in: org.ppbni.splatter.model.UserAdmin.korwil, referenced property unknown: org.ppbni.splatter.model.Korwil.useradmin` when I run the application ~
this is the erd,
this is my kode_pos class
package org.ppbni.splatter.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.MapsId;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import javax.persistence.CascadeType;
@SuppressWarnings("serial")
@Entity
@Table(name="kode_pos")
public class KodePos implements Serializable{
@Id
@Column(name="kode_pos", unique=true, nullable=false)
private String kode_pos;
@Column(name="kelurahan")
private String kelurahan;
@Column(name="kecamatan")
private String kecamatan;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="kode_korwil")
private Korwil korwil;
/**Setter and Getter Methods**/
}
this is my korwil class,
package org.ppbni.splatter.model;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.CascadeType;
@SuppressWarnings("serial")
@Entity
@Table(name="korwil")
public class Korwil implements Serializable{
@Id
@Column(name="kode_korwil", unique=true, nullable=false)
private String kode_korwil;
@Column(name="nama_korwil")
private String nama_korwil;
@Column(name="alias_jabatan")
private String alias_jabatan;
@Column(name="jabatan_korwil")
private String jabatan_korwil;
@OneToMany(fetch = FetchType.LAZY, mappedBy="korwil")
private Set<KodePos> kodepos;
@OneToOne
@MapsId
@JoinColumn(name="no_dana")
private UserAdmin useradmin;
/**Setter and Getter Methods**/
}
this is my user class,
package org.ppbni.splatter.model;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.OneToOne;
import javax.persistence.CascadeType;
@SuppressWarnings("serial")
@Entity
@Table(name="user")
public class UserAdmin implements Serializable{
@Id
@GeneratedValue
@Column(name="no_dana", unique=true, nullable=false)
private String no_dana;
@Column(name="npp")
private String npp;
@Column(name="password")
private String password;
@OneToOne(mappedBy="useradmin", cascade=CascadeType.ALL)
private Wafat wafat;
@OneToOne(mappedBy="useradmin", cascade=CascadeType.ALL)
private Korwil korwil;
/**other field**//
/**setter and gettter methods**/
}
this is my wafat class,
package org.ppbni.splatter.model;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@SuppressWarnings("serial")
@Entity
@Table(name="wafat")
public class Wafat implements Serializable{
@Id
@Column(name="kode_wafat", unique=true, nullable=false)
private String kode_wafat;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="tgl_wafat")
private Date tgl_wafat;
@Column(name="usia_wafat")
private int usia_wafat;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="tgl_makam")
private Date tgl_makam;
@Column(name="tempat_makam")
private String tempat_makam;
@OneToOne
@MapsId
@JoinColumn(name="no_dana")
private UserAdmin useradmin;
/**Setter and Getter Methods**/
}
this is my controller,
@SuppressWarnings("deprecation")
@RequestMapping(value="/user/daftar-anggota-ppbni.html")
public ModelAndView userDaftarAnggotaPPBNI(ModelMap model, HttpServletRequest request, HttpServletResponse response)throws Exception{
SessionFactory factory = new Configuration().configure().buildSessionFactory();
Session session = factory.openSession();
String nama = request.getParameter("nama");
String kota = request.getParameter("kota");
System.out.println(nama);
System.out.println(kota);
Query query = session.createQuery("from UserAdmin where (nama_depan = :namadepan or nama_tengah = :namatengah or nama_belakang = :namabelakang) or kota = :kota");
query.setParameter("namadepan", nama);
query.setParameter("namatengah", nama);
query.setParameter("namabelakang", nama);
query.setParameter("kota", kota);
System.out.println(query);
@SuppressWarnings("unchecked")
List <UserAdmin> result = query.list();
for(int i=0; i < result.size(); i++){
model.addObject("result", result);
}
session.close();
factory.close();
return userDaftarAnggota(model);
}
and this is the error,
org.hibernate.AnnotationException: Unknown mappedBy in: org.ppbni.splatter.model.UserAdmin.korwil, referenced property unknown: org.ppbni.splatter.model.Korwil.useradmin at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:152) at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1686) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1393) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1826) at org.ppbni.splatter.web.controller.UserController.userDaftarAnggotaPPBNI(UserController.java:97) 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.doPost(FrameworkServlet.java:838) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 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)
any help will be pleasure :)
@GeneratedValue
forprivate String no_dana;
in theUserAdmin
looks strange. – v.ladynev