web-dev-qa-db-ja.com

注釈の重複エラー-しかし、どこに?

簡単に言うと、最初に次の例外メッセージが表示されます。

serverError: class javax.faces.el.EvaluationException Duplicate annotation for class: interface javax.validation.constraints.Size: @javax.validation.constraints.Size(groups=[], min=0, message={javax.validation.constraints.Size.message}, payload=[], max=128)

私のコードは、テーブルの1つのエンティティクラス、EJB、「ビジネスクラス」、およびJSFページで構成されています。 EntityManager.merge()を呼び出すと例外が発生します。 'max = 128'の注釈は1つだけあります。

@Size(max = 128)
@Column(name = "name")
private String name;

重複した注釈がある唯一の場所は次のとおりです。

@Entity
@Table(name = "attributes", schema = "office_db")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Attributes.findAll", query = "SELECT a FROM Attributes a"),
    @NamedQuery(name = "Attributes.findById", query = "SELECT a FROM Attributes a WHERE a.id = :id"),
    @NamedQuery(name = "Attributes.findByName", query = "SELECT a FROM Attributes a WHERE a.name = :name"),
    @NamedQuery(name = "Attributes.findByType", query = "SELECT a FROM Attributes a where a.type.id = :type")
})

しかし、Netbeans 8.2によってデータベーステーブルから生成されているため、これは合法であると思います。

次に、もう少し詳しく説明します。最初のテーブル:

mysql> show create table attributes\G
*************************** 1. row ***************************
       Table: attributes
Create Table: CREATE TABLE `attributes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `parent` int(11) DEFAULT NULL,
  `type` int(11) DEFAULT NULL,
  `name` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `parent_ix` (`parent`),
  KEY `type_ix` (`type`),
  CONSTRAINT `attributes_parent_fk` FOREIGN KEY (`parent`) REFERENCES `attributes` (`id`),
  CONSTRAINT `attributes_type_fk` FOREIGN KEY (`type`) REFERENCES `attributes` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1301 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
1 row in set (0.03 sec)

次にEntityクラス:

import (...stuff...)

@Entity
@Table(name = "attributes")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Attributes.findAll", query = "SELECT a FROM     Attributes a"),
    @NamedQuery(name = "Attributes.findById", query = "SELECT a FROM Attributes a WHERE a.id = :id"),
    @NamedQuery(name = "Attributes.findByName", query = "SELECT a FROM Attributes a WHERE a.name = :name"),
    @NamedQuery(name = "Attributes.findByType", query = "SELECT a FROM Attributes a where a.type.id = :type")
})
public class Attributes implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Size(max = 128)
    @Column(name = "name")
    private String name;
    @OneToMany(mappedBy = "parent")
    private Collection<Attributes> attributesCollection;
    @JoinColumn(name = "parent", referencedColumnName = "id")
    @ManyToOne
    private Attributes parent;
    @OneToMany(mappedBy = "type")
    private Collection<Attributes> attributesCollection1;
    @JoinColumn(name = "type", referencedColumnName = "id")
    @ManyToOne
    private Attributes type;
    private static final Logger logger=
            Logger.getLogger(Attributes.class.getName());

    public Attributes() {
    }

    public Attributes(Integer id) {
        this.id = id;
    }
    public Attributes(Integer id, Integer parent, Integer type, String name) {
        logger.info("OFFICE Attributes constructor 3 id: "+id+", parent:     "+parent+", type: "+type+", name: "+name);
        this.parent=new Attributes();
        this.type=new Attributes();
        this.id = id;
        this.parent.setId(parent);
        this.type.setId(type);
        this.name = name;
    }

    public Attributes(Integer parent, Integer type, String name) {
        logger.info("OFFICE Attributes constructor 4 parent: "+parent+", type: "+type+", name: "+name);
        this.parent=new Attributes();
        this.type=new Attributes();
        this.parent.setId(parent);
        this.type.setId(type);
        this.name = name;
        logger.info("OFFICE Attributes constructor 4a");
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<Attributes> getAttributesCollection() {
        return attributesCollection;
    }

    public void setAttributesCollection(Collection<Attributes> attributesCollection) {
        this.attributesCollection = attributesCollection;
    }

    public Attributes getParent() {
        return parent;
    }

    public void setParent(Attributes parent) {
        this.parent = parent;
    }

    @XmlTransient
    public Collection<Attributes> getAttributesCollection1() {
        return attributesCollection1;
    }

    public void setAttributesCollection1(Collection<Attributes> attributesCollection1) {
        this.attributesCollection1 = attributesCollection1;
    }

    public Attributes getType() {
        return type;
    }

    public void setType(Attributes type) {
        this.type = type;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Attributes)) {
            return false;
        }
        Attributes other = (Attributes) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "docdb.Attributes[ id=" + id + " ]";
    }
}

EJBまたはセッションクラス:

import (...stuff...)

@Stateless
public class AttributesSession {
    @PersistenceContext(unitName ="officePU")
    private EntityManager em;
    private static final Logger logger=
            Logger.getLogger(AttributesSession.class.getName());

    public List<Attributes>findAttributes(){
        TypedQuery<Attributes> query=
                    em.createNamedQuery("Attributes.findAll",Attributes.class);
        return query.getResultList();
    }

    public Attributes findAttributeById(Long id){
        TypedQuery<Attributes> query=
                em.createNamedQuery("Attributes.findById", Attributes.class);
        query.setParameter("id", id);
        return query.getSingleResult();
    }

    public Integer findChildCount(Long id){
        TypedQuery<Integer> query=em.createNamedQuery("findChildCount",Integer.class);
        query.setParameter("id", id);
        return query.getSingleResult();
    }

    public String createAttributes(Attributes attr){
        String msg="";

        try{
            em.merge(attr);
            em.flush();
        }
        catch (PersistenceException e){
            msg=e.getMessage();
        }
        return msg;
    }

    public String deleteAttributes(Attributes attr){
        String msg = "";

        try{
            em.remove(em.merge(attr));
            em.flush();
        }
        catch (PersistenceException e){
            msg=e.getMessage();
        }
        return msg;
    }
}

ビジネスまたはコントローラークラス:

import (...stuff...)

@Named(value = "attributesController")
@SessionScoped
public class AttributesController implements Serializable{
    @EJB private AttributesSession sess;
    private Attributes attr;
    private List<Attributes> attrList;
    private Integer id;
    private Integer parent;
    private Integer type;
    private String name;
    private String errmsg;
    private static final Logger logger=
            Logger.getLogger(AttributesController.class.getName());

    public AttributesController() {
        this.attrList = new ArrayList<>();
        this.attr = new Attributes();
    }

    public List<Attributes> getAttrList() {
        return attrList;
    }

    public List<Attributes> getAttrValueList() {
        return attrList;
    }

    ...getters and setters...

    public void clearForm(){
        this.id=null;
        this.name=null;
        this.parent=null;
        this.type=null;
        this.errmsg=null;
    }

    public String createAttributes(){
        if (this.id!=null){
            attr=new Attributes(this.id,this.parent,this.type,this.name);
        }
        else{
            attr=new Attributes(this.parent,this.type,this.name);
        }
        errmsg=sess.createAttributes(attr);
        attrList=sess.findAttributes();
        return "editattributes.xhtml";
    }

    public String deleteAttributes(){
        if (this.id!=null){
            attr=new Attributes(this.id,this.parent,this.type,this.name);
            errmsg=sess.deleteAttributes(attr);
        }
        attrList=sess.findAttributes();
        return "editattributes.xhtml";
    }

    public String listAttributes(){
        attrList=sess.findAttributes();
        return "editattributes.xhtml";
    }

    @PostConstruct
    public void updateList(){
        attrList=sess.findAttributes();
    }

    @Override
    public String toString(){
        return "Name: "+((name==null)?"":name)
                +", parent: "+((parent==null)?"":parent)
                +", type:"+((type==null)?"":type);
    }
}

最後に、スタックトレース:

[2017-10-31T10:23:31.697+0000] [glassfish 5.0] [WARNING] [] [javax.enterprise.resource.webcontainer.jsf.lifecycle] [tid: _ThreadID=27 _ThreadName=http-listener-1(1)] [timeMillis: 1509445411697] [levelValue: 900] [[
  #{attributesController.createAttributes()}: Java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface javax.validation.constraints.Size: @javax.validation.constraints.Size(groups=[], min=0, message={javax.validation.constraints.Size.message}, payload=[], max=128)
javax.faces.FacesException: #{attributesController.createAttributes()}: Java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface javax.validation.constraints.Size: @javax.validation.constraints.Size(groups=[], min=0, message={javax.validation.constraints.Size.message}, payload=[], max=128)
        ...(deleted stuff)
        ... 35 more
Caused by: Java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface javax.validation.constraints.Size: @javax.validation.constraints.Size(groups=[], min=0, message={javax.validation.constraints.Size.message}, payload=[], max=128)
        ... (stuff deleted)
        at docdb.__EJB31_Generated__AttributesSession__Intf____Bean__.createAttributes(Unknown Source)
        at docdb.AttributesController.createAttributes(AttributesController.Java:118)
        at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
        at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
        at Java.lang.reflect.Method.invoke(Method.Java:483)
        at javax.el.ELUtil.invokeMethod(ELUtil.Java:304)
        at javax.el.BeanELResolver.invoke(BeanELResolver.Java:535)
        at javax.el.CompositeELResolver.invoke(CompositeELResolver.Java:256)
        at com.Sun.el.parser.AstValue.invoke(AstValue.Java:285)
        at com.Sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.Java:304)
        at org.jboss.weld.module.web.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.Java:40)
        at org.jboss.weld.module.web.el.WeldMethodExpression.invoke(WeldMethodExpression.Java:50)
        at com.Sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.Java:107)
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.Java:87)
        ... 36 more
]]

[2017-10-31T10:23:31.700+0000] [glassfish 5.0] [INFO] [] [docdb.LifeCycleListener] [tid: _ThreadID=27 _ThreadName=http-listener-1(1)] [timeMillis: 1509445411700] [levelValue: 800] [[
  OFFICE END PHASE INVOKE_APPLICATION 5]]

[2017-10-31T10:23:31.701+0000] [glassfish 5.0] [INFO] [] [docdb.LifeCycleListener] [tid: _ThreadID=27 _ThreadName=http-listener-1(1)] [timeMillis: 1509445411701] [levelValue: 800] [[
  OFFICE]]

[2017-10-31T10:23:31.703+0000] [glassfish 5.0] [SEVERE] [] [javax.enterprise.resource.webcontainer.jsf.context] [tid: _ThreadID=27 _ThreadName=http-listener-1(1)] [timeMillis: 1509445411703] [levelValue: 1000] [[
  javax.faces.el.EvaluationException: Java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface javax.validation.constraints.Size: @javax.validation.constraints.Size(groups=[], min=0, message={javax.validation.constraints.Size.message}, payload=[], max=128)
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.Java:101)
        at com.Sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.Java:102)
        at javax.faces.component.UICommand.broadcast(UICommand.Java:330)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.Java:870)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.Java:1418)
        at com.Sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.Java:82)
        at com.Sun.faces.lifecycle.Phase.doPhase(Phase.Java:100)
        at com.Sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.Java:201)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.Java:670)
        at org.Apache.catalina.core.StandardWrapper.service(StandardWrapper.Java:1580)
        at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:258)
        at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:160)
        at org.Apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.Java:652)
        at org.Apache.catalina.core.StandardPipeline.invoke(StandardPipeline.Java:591)
        at com.Sun.enterprise.web.WebPipeline.invoke(WebPipeline.Java:99)
        at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:155)
        at org.Apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.Java:371)
        at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:238)
        at com.Sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.Java:463)
        at com.Sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.Java:168)
        at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.Java:206)
        at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.Java:180)
        at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.Java:242)
        at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.Java:119)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.Java:284)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.Java:201)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.Java:133)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.Java:112)
        at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.Java:77)
        at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.Java:539)
        at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.Java:112)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.Java:117)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.Java:56)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.Java:137)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.Java:593)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.Java:573)
        at Java.lang.Thread.run(Thread.Java:745)
Caused by: Java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface javax.validation.constraints.Size: @javax.validation.constraints.Size(groups=[], min=0, message={javax.validation.constraints.Size.message}, payload=[], max=128)
        at Sun.reflect.annotation.TypeAnnotationParser.mapTypeAnnotations(TypeAnnotationParser.Java:361)
        at Sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl.<init>(AnnotatedTypeFactory.Java:139)
        at Sun.reflect.annotation.AnnotatedTypeFactory.buildAnnotatedType(AnnotatedTypeFactory.Java:65)
        at Sun.reflect.annotation.TypeAnnotationParser.buildAnnotatedType(TypeAnnotationParser.Java:79)
        at Java.lang.reflect.Field.getAnnotatedType(Field.Java:1159)
        at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findCascadingMetaData(AnnotationMetaDataProvider.Java:610)
        at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findPropertyMetaData(AnnotationMetaDataProvider.Java:231)
        at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getFieldMetaData(AnnotationMetaDataProvider.Java:220)
        at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.retrieveBeanConfiguration(AnnotationMetaDataProvider.Java:128)
        at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfiguration(AnnotationMetaDataProvider.Java:119)
        at org.hibernate.validator.internal.metadata.BeanMetaDataManager.getBeanConfigurationForHierarchy(BeanMetaDataManager.Java:220)
        at org.hibernate.validator.internal.metadata.BeanMetaDataManager.createBeanMetaData(BeanMetaDataManager.Java:187)
        at org.hibernate.validator.internal.metadata.BeanMetaDataManager.lambda$getBeanMetaData$0(BeanMetaDataManager.Java:160)
        at org.hibernate.validator.internal.metadata.BeanMetaDataManager$$Lambda$24/1020030882.apply(Unknown Source)
        at Java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.Java:324)
        at org.hibernate.validator.internal.metadata.BeanMetaDataManager.getBeanMetaData(BeanMetaDataManager.Java:159)
        at org.hibernate.validator.internal.engine.ValidatorImpl.getConstraintsForClass(ValidatorImpl.Java:308)
        at org.Eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.isBeanConstrained(BeanValidationListener.Java:158)
        at org.Eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.validateOnCallbackEvent(BeanValidationListener.Java:108)
        at org.Eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.preUpdate(BeanValidationListener.Java:94)
        at org.Eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.Java:726)
        at org.Eclipse.persistence.descriptors.DescriptorEventManager.notifyEJB30Listeners(DescriptorEventManager.Java:696)
        at org.Eclipse.persistence.descriptors.DescriptorEventManager.executeEvent(DescriptorEventManager.Java:233)
        at org.Eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.calculateChanges(DeferredChangeDetectionPolicy.Java:87)
        at org.Eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy.calculateChangesForExistingObject(AttributeChangeTrackingPolicy.Java:48)
        at org.Eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.Java:711)
        at org.Eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.Java:1566)
        at org.Eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.Java:3256)
        at org.Eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.Java:355)
        at org.Eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.Java:158)
        at org.Eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.Java:68)
        at com.Sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.Java:452)
        at com.Sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.Java:854)
        at com.Sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.Java:723)
        at com.Sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.Java:507)
        at com.Sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.Java:4600)
        at com.Sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.Java:2108)
        at com.Sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.Java:2078)
        at com.Sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.Java:220)
        at com.Sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.Java:88)
        at com.Sun.proxy.$Proxy175.createAttributes(Unknown Source)
        at docdb.__EJB31_Generated__AttributesSession__Intf____Bean__.createAttributes(Unknown Source)
        at docdb.AttributesController.createAttributes(AttributesController.Java:118)
        at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
        at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
        at Java.lang.reflect.Method.invoke(Method.Java:483)
        at javax.el.ELUtil.invokeMethod(ELUtil.Java:304)
        at javax.el.BeanELResolver.invoke(BeanELResolver.Java:535)
        at javax.el.CompositeELResolver.invoke(CompositeELResolver.Java:256)
        at com.Sun.el.parser.AstValue.invoke(AstValue.Java:285)
        at com.Sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.Java:304)
        at org.jboss.weld.module.web.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.Java:40)
        at org.jboss.weld.module.web.el.WeldMethodExpression.invoke(WeldMethodExpression.Java:50)
        at com.Sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.Java:107)
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.Java:87)
        ... 36 more
]]
6
j4nd3r53n

@NamedQueriesが問題である場合、私は驚かれることでしょう。名前は、それが@NamedQueryアイテムのリスト/配列である必要があることを示唆しています。

試してください:

@Column(name = "name", length = 128)
private String name;

実際に@sizeが繰り返されていないことに自信を持っているので、多分関数のオーバーラップを調べる必要があります。@Columnアノテーションに同じ機能が含まれているため、競合が発生している可能性があります。

8
MartinByers

同じ問題が発生しますが、問題はpom.xmlファイルにあります。 2つのjpa依存関係がありました

<dependency>
        <groupId>org.Eclipse.persistence</groupId>
        <artifactId>org.Eclipse.persistence.jpa.modelgen.processor</artifactId>
        <version>2.5.2</version>
        <scope>provided</scope>
</dependency>

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

私は最初のものを削除し、これは私の問題を解決しました。私の英語レベルでごめんなさい

4
Dieudonné

ここでの回答は、この問題を解決するための考えられる解決策をすでに説明しているので、問題の根本原因に関する私の発見の共有に焦点を当てます。

NetBeans 8.2を使用して、[Create Persistence Unit]ボックスをオンにしてエンティティを生成した後、この問題が発生しました。この手順を実行すると、pom.xmlのプロジェクトに2つの依存関係、つまり org.Eclipse.persistence.jpa.modelgen.processor および eclipselink が追加されます。

プロジェクトに追加されたこれらのEclipseLink依存関係には 報告されたバグの問題 がありました:

... @Columnアノテーションが突然他のアノテーションと互換性を失ったようです。

このバグの結果、@ NotNullまたは@Sizeで@Columnアノテーションを使用できなくなります。

2
Tatenda Zifudzi

の中に pom.xmlファイル、削除:

<dependency>
    <groupId>org.Eclipse.persistence</groupId>
    <artifactId>org.Eclipse.persistence.jpa.modelgen.processor</artifactId>
    <version>2.5.2</version>
    <scope>provided</scope>
</dependency>
1
babin souare

私は同じエラーを抱えていたので、エンティティから@NotNullアノテーションを削除して解決しました。

0
EstebanBri

私の場合、次の依存関係があります:

<dependency>
    <groupId>org.Eclipse.persistence</groupId>
    <artifactId>org.Eclipse.persistence.jpa.modelgen.processor</artifactId>
    <version>2.7.4</version>
    <scope>provided</>
</dependency>
<dependency>
    <groupId>org.Eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.5.2</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

私は削除しました:

<dependency>
    <groupId>org.Eclipse.persistence</groupId>
    <artifactId>org.Eclipse.persistence.jpa.modelgen.processor</artifactId>
    <version>2.7.4</version>
    <scope>provided</>
</dependency>

そして今それは大丈夫です。

0
MrMins

このエラーはIDEレベルで存在します。たとえば、次のように注釈が付けられたフィールドuserNameで:

@NotNull
@Size(max = 255)
@Column(name = "user_id", nullable = false, length = 255)
private String userName;

@Sizeおよびlength = 255によってトリガーされた重複エラーをスローします。おそらく、データベースでuser_idのサイズの有効性が設定されていない場合です。また、@NotNullnullable = falseは、DBでnot nullable制約が設定されていない場合にも可能性があります。 NetBeansは、デフォルトで妥当性しないがDBに由来する場合、エンティティの自動生成時にStringフィールドの長さ255を検証することに注意してください。によってスローされたエラーを修正します。

@Column(name = "user_id", nullable = false, length = 255)
private String userName;

OR

@NotNull
@Size(max = 255)
@Column(name = "user_id")
private String userName;

編集:pom.xmlにEclipse-linkとspring-data-jpaの両方が定義されている場合、spring-bootユーザーの場合、エラーが発生する可能性があります。依存関係でEclipseリンクを除外する

0
Xstarz