Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Many-to-Many relations between two entities are not resolved correctly #45

Open
Slebi opened this issue Jan 14, 2021 · 0 comments

Comments

@Slebi
Copy link

Slebi commented Jan 14, 2021

The following relation results (IMHO) in a wrong intermediate table (see below).

Entity A:

@Entity
@Table(name = "measurement")
public class MeasurementEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @OneToMany
    private Set<AmbientSensorReadingEntity> ambientUsedForPreparation;
    
    @OneToMany
    private Set<AmbientSensorReadingEntity> ambientBefore;
    
    @OneToMany
    private Set<AmbientSensorReadingEntity> ambientAfter;

   // ...
}

Entity B:

@Entity
@Table(name = "ambient_sensor_reading")
public class AmbientSensorReadingEntity{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    private double temperature;
// ...
}

Results in the following intermediate table, which can not be used by hibernate:

    create table measurement_ambient_sensor_reading (
       MeasurementEntity_id bigint not null,
        ambientUsedForPreparation_id bigint not null,
        ambientBefore_id bigint not null,
        ambientAfter_id bigint not null,
        primary key (MeasurementEntity_id, ambientAfter_id)
    ) engine=InnoDB;

If I change it to:

    create table measurement_ambient_sensor_reading (
	id bigint not null auto_increment,
       	MeasurementEntity_id bigint not null,
        ambientUsedForPreparation_id bigint,
        ambientBefore_id bigint,
        ambientAfter_id bigint,
        primary key (id)
    ) engine=InnoDB;

Hibernate can correctly use the database. Do I miss some configuration or I am doing something else wrongly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant