NoSuchMethodError when having an Map abstract class extending abstractmap in EclipseLink

Entity Bean inheritance definition

Base superclass extending IdentityhashMap:


public class EntityModel<K extends String, V extends Object> extends IdentityHashMap<String, Object>{

    public EntityModel() {
        super();
    }
    
    
    
}

Entity JPA:

@Entity
@Table(name = "acl_usuario")
@SequenceGenerator(name = "global_seq", sequenceName = "global_seq", allocationSize = 20)
public class Usuario extends EntityModel{

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "global_seq")
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    protected Long id;

    @Basic(optional = false)
    @Column(name = "username", length = 50, nullable = false)
    protected String username;

    @Basic(optional = false)
    @Column(name = "pass", length = 20, nullable = false)
    protected String pass;

    @Basic(optional = false)
    @Column(name = "habilitado", nullable = false)
    protected Boolean habilitado;

    @JoinColumn(name = "rol", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Rol rol;

    @OneToMany(mappedBy = "supervisor", fetch = FetchType.LAZY)
    private Collection<OrdenTrabajo> supervisorCollection;

    @OneToMany(mappedBy = "responsable", fetch = FetchType.LAZY)
    private Collection<OrdenTrabajo> responsableCollection;

    public Usuario() {
        super();
        
    }

    public Long getId() {
        return id;
    }

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

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public Boolean getHabilitado() {
        return habilitado;
    }

    public void setHabilitado(Boolean habilitado) {
        this.habilitado = habilitado;
    }

    public Rol getRol() {
        return rol;
    }

    public void setRol(Rol rol) {
        this.rol = rol;
    }

    public Collection<OrdenTrabajo> getSupervisorCollection() {
        return supervisorCollection;
    }

    public void setSupervisorCollection(Collection<OrdenTrabajo> supervisorCollection) {
        this.supervisorCollection = supervisorCollection;
    }

    public Collection<OrdenTrabajo> getResponsableCollection() {
        return responsableCollection;
    }

    public void setResponsableCollection(Collection<OrdenTrabajo> responsableCollection) {
        this.responsableCollection = responsableCollection;
    }

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

    @Override
    public boolean equals(Object obj) { 
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Usuario other = (Usuario) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

}

With Eclipselink default configuration got NoSuchMethodError.

The fix

Disable eclipselink.weaving.internal configuration. (https://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/p_weaving_internal.htm)

In persistence.xml


  <property name="eclipselink.weaving.internal" value="false"/>

In property map


propertiesMap.put(PersistenceUnitProperties.WEAVING_INTERNAL, "false");

In Spring


<bean id="jpaVendorAdapter" class="de.mischur.library.utils.ExtendedEclipseLinkJpaVendorAdapter">
    <property name="weavingInternal" value="false">
</property></bean>

JPA Global Sequence provider EJB Singleton


package com.origami.censocat.service;

import java.util.concurrent.atomic.AtomicLong;
import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Singleton;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * @author Fernando
 */
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
@Lock(LockType.WRITE)
public class GlobalSequenceProvider implements GlobalSequenceProviderLocal {
    
    @PersistenceContext(unitName = "CensoCat_PU")
    private EntityManager em;
    
    private Long actualId;
    private Long limitId;
    private final Long interval = 20L;

    public GlobalSequenceProvider() {
    }
    
    protected Boolean esDisponible(){
        if(actualId==null || actualId>=limitId){
            return false;
        }
        return true;
    }
    
    @Override
    public Long getNextId(){
        if(!this.esDisponible()){
            // obtener nuevo intervalo de secuencia
            genNextInterval();
        }
        actualId++;
        return actualId;
    }
    
    protected void genNextInterval(){
        Query q = em.createNativeQuery("select nextval('global_seq')");
        actualId = (Long)q.getSingleResult();
        limitId = actualId + interval;
    }
    
}

Apache Tomee 1.7 Plume Datasource configuration

In this example we will configure an postgresql datasource.

First download an place in /lib folder the postgresql JDBC driver jar

Open /conf/tomee.xml and put the datasource resource block:

<?xml version="1.0" encoding="UTF-8"?>
<tomee>
  <!-- see http://tomee.apache.org/containers-and-resources.html -->
  
  <Resource id="censocat_db" type="DataSource">
    #  PostgreSQL connection
    JdbcDriver   org.postgresql.Driver
    JdbcUrl  jdbc:postgresql://localhost/censocat
    UserName     sisapp
    Password     sis98
  </Resource>
  
</tomee>

Persistence.xml configuration:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="CensoCat_PU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>censocat_db</jta-data-source>
    <shared-cache-mode>NONE</shared-cache-mode>
    <properties>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
      <property name="eclipselink.ddl-generation.output-mode" value="database"/>
    </properties>
  </persistence-unit>
</persistence>

EJB injection of EM:

    @PersistenceContext(unitName = "CensoCat_PU")
    private EntityManager entityManager;

Common DataSource Configurations share [gp] share [fb] share [tw] share [pin] contribute
See the DataSource Configuration for details on all configuration options for DataSources.

HSQLDB
The drivers are included with OpenEJB 3.0 and HSQLDB is the default database.

<Resource id="HSQLDB Database" type="DataSource">
    JdbcDriver org.hsqldb.jdbcDriver
    JdbcUrl jdbc:hsqldb:file:hsqldb
    UserName sa
    Password
</Resource>

Derby (Embedded)

<Resource id="Derby Database" type="DataSource">
    #Embedded Derby example

    JdbcDriver org.apache.derby.jdbc.EmbeddedDriver
    JdbcUrl jdbc:derby:derbyDB;create=true
    UserName admin
    Password pass
</Resource>

MySQL

<Resource id="MySQL Database" type="DataSource">
    #  MySQL example
    #
    #  This connector will not work until you download the driver at:
    #  http://www.mysql.com/downloads/api-jdbc-stable.html

    JdbcDriver  com.mysql.jdbc.Driver
    JdbcUrl jdbc:mysql://localhost/test
    UserName    test
</Resource>

Oracle

<Resource id="Oracle Database" type="DataSource">
    #  Oracle example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.OracleDriver
    JdbcUrl jdbc:oracle:thin:@localhost:1521:orcl
    UserName    scott
    Password    tiger
</Resource>

OracleXA

<Resource id="OracleXA Database" type="DataSource">
    #  OracleXA example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.xa.client.OracleXADataSource
    JdbcUrl jdbc:oracle:thin:@localhost:1521:orcl
    UserName    scott
    Password    tiger
</Resource>

PosgreSQL

<Resource id="PostgreSQL Database" type="DataSource">
    #  PostgreSQL example
    #
    #  This connector will not work until you download the driver at:
    #  http://jdbc.postgresql.org/download.html
    JdbcDriver   org.postgresql.Driver
    JdbcUrl  jdbc:postgresql://localhost/test
    UserName     postgres
    Password     pass
</Resource>

InstantDB

<Resource id="InstantDB Database" type="DataSource">
    #  InstantDB example
    #
    JdbcDriver   org.enhydra.instantdb.jdbc.idbDriver
    JdbcUrl  jdbc:idb:conf/instantdb.properties
    UserName     Admin
    Password     pass
</Resource>

Internally, from TomEE 1.5.0, JDBC pools are managed via Tomcat-pool. You can still switch back to Apache Commons DBCP by adding the following property: DataSourceCreator dbcp. To get the full list of available configuration properties, have a look to Apache Commons DBCP configuration.