AnnotationException

I have these errors and don’t understand Thanks.
OUTPUT:
mag 13, 2021 11:31:48 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 5.4.30.Final
mag 13, 2021 11:31:49 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager
INFO: HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
mag 13, 2021 11:31:49 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
mag 13, 2021 11:31:49 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost/Parlamento]
mag 13, 2021 11:31:49 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {password=, user=postgres}
mag 13, 2021 11:31:49 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
mag 13, 2021 11:31:49 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
mag 13, 2021 11:31:50 AM org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
mag 13, 2021 11:31:51 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@7a18e8d] for (non-JTA) DDL execution was not in auto-commit mode; the Connection ‘local transaction’ will be committed and the Connection will be set into auto-commit mode.
mag 13, 2021 11:31:51 AM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
mag 13, 2021 11:31:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
mag 13, 2021 11:31:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost/Parlamento]
mag 13, 2021 11:31:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {password=
, user=postgres}
mag 13, 2021 11:31:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
mag 13, 2021 11:31:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
mag 13, 2021 11:31:51 AM org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
Exception in thread “main” org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: swt.mvn.Parlamento.src.Servlet_Parlamento.Parlamentari.Parlamentare.periodo_carica[swt.mvn.Parlamento.src.Servlet_Parlamento.Parlamentari.Range2]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1351)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:874)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:799)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:53)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1693)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1661)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:295)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:86)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:479)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
at swt.mvn.Parlamento.App.main(App.java:130)

Parlamentare.java

@Entity
@Table(name = "parlamentari")
@IdClass(PK.class)
public class Parlamentare implements Serializable{

	@Id
	@GeneratedValue(strategy= GenerationType.AUTO)
	@Column(name = "nome")
	 String nome;
	@Id
	@Column(name = "partito")
	 String partito;
	@Id
	@Column(name = "circoscrizione")
	 String circoscrizione;
	 Date data_nascita; 
     String luogo; 
     String titolo_studi; 
     String[] mandati; 
     String[] commissioni;
     
     @OneToMany(mappedBy="parlamentare",
    		 targetEntity = Range2.class)
    		// cascade = CascadeType.ALL, 
    		// orphanRemoval = true,
    		// fetch=FetchType.EAGER)//fetch=FetchType.EAGER)//cascade = CascadeType.ALL, orphanRemoval = true)//targetEntity = Range2.class,fetch=FetchType.EAGER)
 	private List<Range2<LocalDate>> periodo_carica = new ArrayList<Range2<LocalDate>>();
.........

PK.java

@Entity(name = "Parlamentare")
@IdClass(PK.class)
public class PK implements Serializable {
    @Id
    String nome;
    @Id
    String partito;
    @Id
    String circoscrizione;

	public PK(String nome, String partito, String circoscrizione) {
		super();
		this.nome = nome;
		this.partito = partito;
		this.circoscrizione = circoscrizione;
	}
............

Range2.java (is the same as Vlad Mihalcea’s Range.java vladmihalcea.com/map-postgresql-range-column-type-jpa-hibernate/ )

  @ManyToOne(targetEntity = Parlamentare.class)//, fetch=FetchType.LAZY)
    private Parlamentare parlamentare;

App.java

public class App 
{
	private static ServiceRegistry serviceregistry;
	private static SessionFactory sf;
	public static SessionFactory getSessionFactory() {
        if (sf == null) {
            StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure().build();
            Metadata metadata = new MetadataSources(standardRegistry).getMetadataBuilder().build();
            sf = metadata.getSessionFactoryBuilder().build();
        }
        return sf;
    }
	
    public static void main( String[] args )throws ParseException, NullPointerException{
    	...
     Configuration con  = new Configuration().configure().addAnnotatedClass(Parlamentare.class).addAnnotatedClass(Range2.class);      
        
	     //serviceregistry.applySettings(con.getProperties()).buildServiceRegistry();
	    getSessionFactory();

        serviceregistry = new StandardServiceRegistryBuilder().applySettings(con.getProperties()).build();
        try {
     sf = con.buildSessionFactory(serviceregistry);
        } catch (NullPointerException e) {
        	e.printStackTrace();
        }
        Session session = sf.openSession();
        session.beginTransaction();	
	
        Parlamentare parlamentare = (Parlamentare) session.get(Parlamentare.class, //parlamentare.getpk("Abate Rosa Silvana","M5S", "Calabria"));
				new Parlamentare("Abate Rosa Silvana","M5S", "Calabria"));
        
	
		
		parlamentare.toString();
		System.out.println(parlamentare);
		
		System.out.println(parlamentare.getNome());
		System.out.println(parlamentare.getPartito());
		System.out.println(parlamentare.getCircoscrizione());
		System.out.println(parlamentare.getData_nascita());
		System.out.println(parlamentare.getLuogo());
		System.out.println(parlamentare.getTitolo_studi());
		System.out.println(parlamentare.getMandati()); 
		System.out.println(parlamentare.getCommissioni()); 
		System.out.println(parlamentare.getPeriodo_carica());
	
        
        List<Range2<LocalDate>> periodo_carica = parlamentare.getPeriodo_carica();
        		//new ArrayList<Range2<LocalDate>>();
      //  periodo_carica = parlamentare.getPeriodo_carica();
        String range="a";
        for(Range2<LocalDate> dr : periodo_carica)
        {
        	System.out.println(dr.toString());
        	System.out.println(dr.localDateRange(range));
        }

        session.getTransaction().commit();
       // tx.commit();
        session.close();
        sf.close();
    }
    
}

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost/Parlamento</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password"></property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="show_sql">true</property>
    </session-factory>
</hibernate-configuration>

This mapping you did tells Hibernate that Range2 is an entity, and the definition of the join columns is located in an attribute named parlamentare within Range2 which I guess is not what you want?

You will probably want to map this as @ElementCollection like this:

@ElementCollection
@CollectionTable(name = "periods")
List<Range2<LocalDate>> periodo_carica = new ArrayList<Range2<LocalDate>>();

In fact no, thanks!!!