0
package emp;

import java.io.Serializable;
import javax.persistence.*;


@Entity
@Access(AccessType.FIELD)
public class Oacle implements Serializable {


private static final String loc_code ="619";

@Id
private int id;
@Transient
private String phnoenum;

public Oacle() {
    super();
}

public int getid(){return id;}
public void setid(int id){this.id=id;}

public String getphoneno(){return phnoenum;};
public void setphoneno(String num){ this.phnoenum=num;};



@Access(AccessType.PROPERTY) @Column(name="phone")//THIS LINE CASUSES THE PROBLEM

protected String grno()
{
   if(phnoenum.length()==10)
       return phnoenum;
   else
       return loc_code+phnoenum;
}

protected void setphno(String num)
{
   if(num.startsWith(loc_code))
       phnoenum=num.substring(3);
   else
       phnoenum=num;
}

    }

- - - - - - - - - - -错误 - - - - - - - - - - - - - - -------------------------------------

Exception in thread "main" Local Exception Stack: 
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.3.3.v20120629-r11760): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@63d12a6
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.3.v20120629-r11760): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [OPERTION JPA] failed.
Internal Exception: Exception [EclipseLink-7174] (Eclipse Persistence Services - 2.3.3.v20120629-r11760): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The getter method [method grno] on entity class [class emp.Oacle] does not have a corresponding setter method defined.
    at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:115)
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:73)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:61)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.3.v20120629-r11760): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [OPERTION JPA] failed.
Internal Exception: Exception [EclipseLink-7174] (Eclipse Persistence Services - 2.3.3.v20120629-r11760): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The getter method [method grno] on entity class [class emp.Oacle] does not have a corresponding setter method defined.
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1402)
    at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:105)
    ... 3 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.3.v20120629-r11760): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [OPERTION JPA] failed.
Internal Exception: Exception [EclipseLink-7174] (Eclipse Persistence Services - 2.3.3.v20120629-r11760): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The getter method [method grno] on entity class [class emp.Oacle] does not have a corresponding setter method defined.
    at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:221)
    ... 6 more
Caused by: Exception [EclipseLink-7174] (Eclipse Persistence Services - 2.3.3.v20120629-r11760): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The getter method [method grno] on entity class [class emp.Oacle] does not have a corresponding setter method defined.
    at org.eclipse.persistence.exceptions.ValidationException.noCorrespondingSetterMethodDefined(ValidationException.java:1909)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataMethod.isValidPersistenceMethod(MetadataMethod.java:247)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataMethod.isValidPersistenceMethod(MetadataMethod.java:226)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessorMethods(ClassAccessor.java:445)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessorFields(ClassAccessor.java:426)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessors(ClassAccessor.java:389)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.preProcess(ClassAccessor.java:1155)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor.preProcess(MappedSuperclassAccessor.java:693)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.preProcess(EntityAccessor.java:554)
    at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage1(MetadataProject.java:1617)
    at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:531)
    at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:526)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1337)
    ... 5 more
4

1 回答 1

0

你的方法 grno() 应该被称为 getPhno() 并且你的 set 方法应该是 setPhno(),或者使它成为一个字段而不是使用属性访问。但是代码实际上没有任何意义。

见, http ://en.wikibooks.org/wiki/Java_Persistence

于 2013-07-08T14:00:01.187 回答