Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Exception [TOPLINK-48] Multiple writable mappings exist for field

652974Jul 10 2009 — edited Jul 20 2009
Hi All
I am quite new to JPA and Toplink and I am trying to write simple JPA application using toplink essentials as the persistence provider however, when I comppile the code, get errors below saying that Multiple writable mappings exist for a given field i.e. [J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]. The thing is, I havent tried to map this field i.e. J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE to multiple maps so I'm a bit confused as to why I'm getting this error. I have attached all the the associated code and error messages. I was hoping that some one will be able to help


The error are
Runtime Exceptions:
---------------------------------------------------------
; nested exception is:
javax.persistence.PersistenceException: Exception [TOPLINK-0] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------

Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]. Only one may be defined as writable, all others must be specified read-only.
Mapping: oracle.toplink.essentials.mappings.DirectToFieldMapping[branch_Addr_Road_Name-->J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]
Descriptor: RelationalDescriptor(com.gworx.Bank --> [DatabaseTable(J2EEUSER.BANKS)])

Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]. Only one may be defined as writable, all others must be specified read-only.
Mapping: oracle.toplink.essentials.mappings.DirectToFieldMapping[bankName-->J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]
Descriptor: RelationalDescriptor(com.gworx.Bank --> [DatabaseTable(J2EEUSER.BANKS)])

Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]. Only one may be defined as writable, all others must be specified read-only.
Mapping: oracle.toplink.essentials.mappings.DirectToFieldMapping[branch_Addr_Locality-->J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]
Descriptor: RelationalDescriptor(com.gworx.Bank --> [DatabaseTable(J2EEUSER.BANKS)])

Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]. Only one may be defined as writable, all others must be specified read-only.
Mapping: oracle.toplink.essentials.mappings.DirectToFieldMapping[branch_Addr_City-->J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]
Descriptor: RelationalDescriptor(com.gworx.Bank --> [DatabaseTable(J2EEUSER.BANKS)])

Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]. Only one may be defined as writable, all others must be specified read-only.
Mapping: oracle.toplink.essentials.mappings.DirectToFieldMapping[branchName-->J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]
Descriptor: RelationalDescriptor(com.gworx.Bank --> [DatabaseTable(J2EEUSER.BANKS)])

Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]. Only one may be defined as writable, all others must be specified read-only.
Mapping: oracle.toplink.essentials.mappings.DirectToFieldMapping[branch_Addr_Postcode-->J2EEUSER.BANKS.BRANCH_ADDR_POSTCODE]
Descriptor: RelationalDescriptor(com.gworx.Bank --> [DatabaseTable(J2EEUSER.BANKS)])

Exception [TOPLINK-46] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: There should be one non-read-only mapping defined for the primary key field [J2EEUSER.ACCOUNTS.SORTCODE].
Descriptor: RelationalDescriptor(com.gworx.Account --> [DatabaseTable(J2EEUSER.ACCOUNTS)])


The entity class is
package com.gworx;
import java.io.Serializable;

import javax.persistence.*;
import javax.persistence.CascadeType;

@Entity
@IdClass(BankPK.class)


@Table(name = "BANKS", schema = "J2EEUSER")
public class Bank implements Serializable {
	

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "BRANCH_SORTCODE", nullable = false, precision = 6, insertable=false, updatable=false)
	long sortcode;
	
	@Basic()
	@Column(name = "BANK_NAME", nullable = false, insertable=false, updatable=false)
	String  bankName;
	
	@Basic()
	@Column(name = "BRANCH_NAME", nullable = false, insertable=false, updatable=false)
	String branchName;
	
	@Basic()
	@Column(name = "BRANCH_ADDR_HOUSE_NAME", nullable = false, insertable=false, updatable=false)
	String branch_Addr_House_Name;
	
	@Basic()
	@Column(name = "BRANCH_ADDR_ROAD_NAME",nullable = false, insertable=false, updatable=false)
	String branch_Addr_Road_Name;
	@Basic()
	@Column(name = "BRANCH_ADDR_LOCALITY", nullable = false, insertable=false, updatable=false)
	String branch_Addr_Locality;
	@Basic()
	@Column(name = "BRANCH_ADDR_CITY",nullable = false, insertable=false, updatable=false)
	String branch_Addr_City;
	@OneToOne(cascade=CascadeType.ALL)
	@Basic()
	@Column(name = "BRANCH_ADDR_POSTCODE", nullable = false)
	String branch_Addr_Postcode;
	
	public Bank(){}
	
	public Bank(
	               String bankName,
		String branchName,
		long sortcode,
		String  branch_Addr_House_Name,
    		String  branch_Addr_Road_Name,
    		String  branch_Addr_Locality,
    		String  branch_Addr_City,
    		String  branch_Addr_Postcode)

                 { 
		this.bankName=bankName;
		this.sortcode=sortcode;
		this.branchName = branchName;
	                this.branch_Addr_House_Name=branch_Addr_House_Name;
		this.branch_Addr_Road_Name=branch_Addr_Road_Name;
		this.branch_Addr_Locality=branch_Addr_Locality;
		this.branch_Addr_City=branch_Addr_City;  
		this.branch_Addr_Postcode=branch_Addr_Postcode;
		
	}
	
	public void setSortcode(long sortcode){
		this.sortcode =sortcode;
	}
	
	public long getSortCode(){
		return this.sortcode;
	}
The PK class is
public class BankPK implements Serializable {
	
	public long sortcode;

	public BankPK(long sortcode){
		this.sortcode = sortcode;
	}

	public boolean equals(Object obj){
		
		if(obj==null || !(obj instanceof BankPK)){
		
			return false;
		}
		else if (((BankPK)obj).sortcode ==sortcode)
		return true;
		else
			return false;
		
	}
	
	public int hashCode(){

		StringBuffer buff = new StringBuffer();
		buff.append(sortcode);
		int hashCode =buff.hashCode();
		return hashCode;
	}
	

}
My stateless session bean that I use to create to create the entity is
package com.gworx;

import javax.ejb.Local;

import javax.ejb.Stateless;
import javax.persistence.*;
import javax.ejb.Remote;
import com.gworx.BankBeanRemote;



/**
 * Session Bean implementation class BankBean
 */
@Stateless

public class BankBean implements BankBeanRemote {

    /**
     * Default constructor. 
     */
	
	
	@PersistenceContext
	
	
	EntityManager entMgr;
	//public Bank bank; 
	
	public Account account;
	
	long sortcode, cust_id;
	
	//Bank Details
	String  bankName,branchName,branch_Addr_House_Name,
	branch_Addr_Road_Name,branch_Addr_Locality, 
	branch_Addr_City,  branch_Addr_Postcode;
	
	
	//Customer specific Details
	String cust_Surname,cust_Middlename,cust_Forename,
	cust_Addr_HouseName,cust_Addr_RoadName,
	cust_Addr_Locality,cust_Addr_City,cust_Addr_PostCode;
	
    public BankBean() {
        // TODO Auto-generated constructor stub
    //	entMgr=emf.createEntityManager();
    }

   
   public void  make_A_Bank(
		   String bankName,
    		String branchName,
    		long sortcode,
    		String  branch_Addr_House_Name,
    		String  branch_Addr_Road_Name,
    		String  branch_Addr_Locality,
    		String  branch_Addr_City,
    		String  branch_Addr_Postcode
    		)

                               {
	   	this.sortcode=sortcode;
	   	this.bankName =bankName;
	   	this.branchName = branchName;
	                this.branch_Addr_House_Name=branch_Addr_House_Name;
		this.branch_Addr_Road_Name=branch_Addr_Road_Name;
		this.branch_Addr_Locality=branch_Addr_Locality;
		this.branch_Addr_City=branch_Addr_City;  
		this.branch_Addr_Postcode=branch_Addr_Postcode;
		
		Bank bank = new Bank( bankName,branchName,sortcode,branch_Addr_House_Name,
				branch_Addr_Road_Name,branch_Addr_Locality, 
				branch_Addr_City,  branch_Addr_Postcode);
		entMgr.persist(bank);
		
		//return bank;
    }


public void make_An_Account(Bank bank, Customer customer, long accNum,
		AccountType accType) {
	
	Bank tempbank = entMgr.find(Bank.class, bank.getSortCode());
	Customer  tempcust=entMgr.find(Customer.class, customer.getCustomerPK());
	Account acc = new Account(tempbank, tempcust, accNum, accType );
	entMgr.persist(acc);
	
	//return acc;
}


public void make_A_Customer(String cust_Surname,
		String cust_Middlename, String cust_Forename,
		String cust_Addr_HouseName, String cust_Addr_RoadName,
		String cust_Addr_Locality, String cust_Addr_City,
		String cust_Addr_PostCode) {
	
	
	Customer cust = new Customer(cust_Surname,cust_Middlename,cust_Forename,
			cust_Addr_HouseName,cust_Addr_RoadName,
			cust_Addr_Locality,cust_Addr_City,cust_Addr_PostCode);
	
	entMgr.persist(cust);
	
	//return null;
}


public void make_A_Bank() {
	// TODO Auto-generated method stub
	
}
    
    
}
The Client application is
package com.gworx.client;
import javax.ejb.EJB;

import com.gworx.BankBeanRemote;

public class BankClient {

	/**
	 * @param args
	 */
@EJB 
private  static BankBeanRemote testbean;

public BankClient(){
	
}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
			
				testbean.make_A_Bank(
				"Test_Bank_Name", 
				"Test_Bank_Branch_Name", 
				010102,
				"Test_House",
				"Test_Road_Name", 
				"Test_branch_Locality", 
				"Test_branch_City", 
				"E2 8DY");
		System.out.println("Bank Created, Check DB tables to verify creation!!");
	}

}
Thanks

Edited by: Geedo on 16-Jul-2009 10:06
This post has been answered by james_sutherland on Jul 16 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 17 2009
Added on Jul 10 2009
6 comments
6,513 views