Gwt ve Jpa ile uygulama geliştiriyorum. Customer, CustomerContact, CustomerTarget vb. daha birçok entity kullanarak çalışıyorum. Daha önce veritabanından bu entity yardımı ile istediğim verileri çekebiliyor, güncelleme yapabiliyordum. Müşterinin son bilgilerini geçici bir tabloda saklama ihtiyacı duydum ve bu nedenle CustomerTemp, CustomerContactTemp, CustomerTargetTemp vb. entity oluşturdum ve tabii ki bunların veritabanındaki karşılığı olan tabloları da oluşturdum. Entitylerin her birini birbiriyle ilişkilendirmeme ve persistence.xml dosyasına entityleri yazmama rağmen aşağıdaki hatayı alıyorum.
Error occured while establishing connection to DB : Exception [EclipseLink-0] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------
Exception [EclipseLink-48] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [LGOLD.dbo.CRMConfirmationLogs.FirmCustomerId]. Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[firmCustomer]
Descriptor: RelationalDescriptor(com.server.entity.ConfirmationLog --> [DatabaseTable(LGOLD.dbo.CRMConfirmationLogs)])
Exception [EclipseLink-48] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [LGOLD.dbo.ProductGroupCapacities.FirmCustomerId]. Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[firmCustomerTemp]
Descriptor: RelationalDescriptor(com.server.entity.ProductGroupCapacity --> [DatabaseTable(LGOLD.dbo.ProductGroupCapacities)])
Exception [EclipseLink-93] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [FirmCustomers] is not present in this descriptor.
Descriptor: RelationalDescriptor(com.server.entity.FirmCustomerTemp --> [DatabaseTable(LGOLD.dbo.FirmCustomersTemp)])
Exception [EclipseLink-41] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.
Descriptor: RelationalDescriptor(com.server.entity.FirmCustomerTemp --> [DatabaseTable(LGOLD.dbo.FirmCustomersTemp)])
Runtime Exceptions:
---------------------------------------------------------
java.sql.SQLException: javax.persistence.PersistenceException: Exception [EclipseLink-0] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------
Exception [EclipseLink-48] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [LGOLD.dbo.CRMConfirmationLogs.FirmCustomerId]. Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[firmCustomer]
Descriptor: RelationalDescriptor(com.server.entity.ConfirmationLog --> [DatabaseTable(LGOLD.dbo.CRMConfirmationLogs)])
Exception [EclipseLink-48] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [LGOLD.dbo.ProductGroupCapacities.FirmCustomerId]. Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[firmCustomerTemp]
Descriptor: RelationalDescriptor(com.server.entity.ProductGroupCapacity --> [DatabaseTable(LGOLD.dbo.ProductGroupCapacities)])
Exception [EclipseLink-93] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [FirmCustomers] is not present in this descriptor.
Descriptor: RelationalDescriptor(com.server.entity.FirmCustomerTemp --> [DatabaseTable(LGOLD.dbo.FirmCustomersTemp)])
Exception [EclipseLink-41] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.
Descriptor: RelationalDescriptor(com.server.entity.FirmCustomerTemp --> [DatabaseTable(LGOLD.dbo.FirmCustomersTemp)])
Runtime Exceptions:
---------------------------------------------------------
at com.server.dao.EntityManagerClient.getEntityManager(EntityManagerClient.java:37)
at com.server.dao.MenuGroupQuery.getMenuGroups(MenuGroupQuery.java:56)
at com.server.dao.MenuGroupQuery.getMenuGroups(MenuGroupQuery.java:39)
at com.server.action.UserAuthorizationActions.getUserMenu(UserAuthorizationActions.java:112)
at com.server.service.UserAuthorizationServices.getUserMenu(UserAuthorizationServices.java:16)
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 com.server.ServiceExecuter.executeService(ServiceExecuter.java:54)
at com.server.ProxyServiceImpl.callService(ProxyServiceImpl.java:171)
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 com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-0] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------
Exception [EclipseLink-48] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [LGOLD.dbo.CRMConfirmationLogs.FirmCustomerId]. Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[firmCustomer]
Descriptor: RelationalDescriptor(com.server.entity.ConfirmationLog --> [DatabaseTable(LGOLD.dbo.CRMConfirmationLogs)])
Exception [EclipseLink-48] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [LGOLD.dbo.ProductGroupCapacities.FirmCustomerId]. Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[firmCustomerTemp]
Descriptor: RelationalDescriptor(com.server.entity.ProductGroupCapacity --> [DatabaseTable(LGOLD.dbo.ProductGroupCapacities)])
Exception [EclipseLink-93] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [FirmCustomers] is not present in this descriptor.
Descriptor: RelationalDescriptor(com.server.entity.FirmCustomerTemp --> [DatabaseTable(LGOLD.dbo.FirmCustomersTemp)])
Exception [EclipseLink-41] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.
Descriptor: RelationalDescriptor(com.server.entity.FirmCustomerTemp --> [DatabaseTable(LGOLD.dbo.FirmCustomersTemp)])
Runtime Exceptions:
---------------------------------------------------------
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:272)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:111)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:163)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:150)
at com.server.dao.EntityManagerClient.getEntityManager(EntityManagerClient.java:27)
... 37 more
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------
Exception [EclipseLink-48] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [LGOLD.dbo.CRMConfirmationLogs.FirmCustomerId]. Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[firmCustomer]
Descriptor: RelationalDescriptor(com.server.entity.ConfirmationLog --> [DatabaseTable(LGOLD.dbo.CRMConfirmationLogs)])
Exception [EclipseLink-48] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [LGOLD.dbo.ProductGroupCapacities.FirmCustomerId]. Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[firmCustomerTemp]
Descriptor: RelationalDescriptor(com.server.entity.ProductGroupCapacity --> [DatabaseTable(LGOLD.dbo.ProductGroupCapacities)])
Exception [EclipseLink-93] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [FirmCustomers] is not present in this descriptor.
Descriptor: RelationalDescriptor(com.server.entity.FirmCustomerTemp --> [DatabaseTable(LGOLD.dbo.FirmCustomersTemp)])
Exception [EclipseLink-41] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.
Descriptor: RelationalDescriptor(com.erver.entity.FirmCustomerTemp --> [DatabaseTable(LGOLD.dbo.FirmCustomersTemp)])
Runtime Exceptions:
---------------------------------------------------------
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:477)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:617)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:227)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
... 41 more
Uygulamamı görmeniz için önemli birkaç dosyanın içeriği:
CustomerTemp.java:
@Entity
@Table(schema = "dbo", catalog = "LGOLD", name = "CustomersTemp")
public class CustomerTemp implements IEntity {
private static final long serialVersionUID = 1L;
public static final int STATUS_NEW = 0;
public CustomerTemp() {
customerContacts = new ArrayList<CustomerContactTemp>();
firmCustomers = new ArrayList<FirmCustomerTemp>();
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "CustomerId")
private int id;
@ManyToOne
@JoinColumn(name = "CustomerTypeId")
private CustomerType customerType;
@ManyToOne
@JoinColumn(name = "SectorId")
private Sector sector;
...
CustomerContactTemp.java
@Entity
@Table(schema="dbo", catalog="LGOLD", name="CustomerContactsTemp")
public class CustomerContactTemp implements IEntity {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="CustomerContactId")
private int id;
@ManyToOne
@JoinColumn(name="CustomerId")
private CustomerTemp customer;
@Column(name="Name")
private String name;
@Column(name="Surname")
private String surname;
@Column(name="Title")
private String title;
@Column(name="Department")
private String department;
...
persistence.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"><persistence-unit name="**">
<class>com.server.entity.CustomerContactTemp</class>
<class>com.server.entity.CustomerTemp</class>
...
ConfirmationLog.java
@Entity
@Table(schema="dbo", catalog="LGOLD", name="CRMConfirmationLogs")
public class ConfirmationLog implements Serializable {
private static final long serialVersionUID = 1L;
public ConfirmationLog() {
super();
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="ConfirmationLogId")
private int id;
@ManyToOne
@JoinColumn(name="FirmCustomerId")
private FirmCustomer firmCustomer;
@ManyToOne
@JoinColumn(name="FirmCustomerId")
private FirmCustomerTemp firmCustomerTemp;
public FirmCustomerTemp getFirmCustomerTemp() {
return firmCustomerTemp;
}
public void setFirmCustomerTemp(FirmCustomerTemp firmCustomerTemp) {
this.firmCustomerTemp = firmCustomerTemp;
}
@Column(name="Type")
private int type;
@Column(name="Time")
private String time;
@ManyToOne
@JoinColumn(name="UserId")
private User user;
@Column(name="Score")
private int score;
@Column(name="Notes")
private String notes;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public FirmCustomer getFirmCustomer() {
return firmCustomer;
}
public void setFirmCustomer(FirmCustomer firmCustomer) {
this.firmCustomer = firmCustomer;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
}
Burada bahsedilen hata neden kaynaklanabilir acaba?
ÇÖZÜM: Sorun FirmCustomerTemp.java'da kullandığım mappedBy'ın yanlış isimlendirilmesinden kaynaklanıyormuş. CustomerTargetTemp.java'da FirmCustomerTemp nesnesi için aşağıdaki gibi ilişki tanımladım:
@ManyToOne
@JoinColumn(name="TempFirmCustomerId")
private FirmCustomerTemp firmCustomerTemp;
FirmCustomerTemp'de ise ilişikiyi aşağıdaki gibi tanımladım sorun çözüldü:
@OneToMany(mappedBy="firmCustomerTemp", fetch=FetchType.LAZY, cascade=PERSIST)
private List<CustomerTargetTemp> customerTargetsTemp;
mappedBy içerisindeki değer, ilişkide bulunduğu nesnesinin kendisiyle eşleşen değeri ile aynı ifadeye sahip olmalıydı.