#IntelliJ generating extra fields in my annotated hibernate classes

12 messages · Page 1 of 1 (latest)

merry fractal
#

This is not strictly SQL but Hibernate: I used the feature intellij has for generating the annotated hibernate classes for my database.

SQL for one table is this:

(
    id int NOT NULL AUTO_INCREMENT,
    tagname varchar(255) NOT NULL,
    simulation_id int NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (simulation_id) REFERENCES simulation(id)
);```

but the generated classes look like this:

```    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "id", nullable = false)
    private int id;

    @Basic
    @Column(name = "tagname", nullable = false, length = 255)
    private String tagname;

    @Basic
    @Column(name = "simulation_id", nullable = false)
    private int simulationId;

    @ManyToOne
    @JoinColumn(name = "simulation_id", referencedColumnName = "id", nullable = false)
    private SimulationEntity simulationBySimulationId;

simulationBySimulationId is a column that doesnt exist on my table.Why was it created? Am i supposed to use it? Why was @ManyToOne not put on simulationId, which is the foreign key on my table?

small cradleBOT
#

This post has been reserved for your question.

Hey @merry fractal! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

tall pivot
#

if you need to get Simulation object as reference from factory - then you need it. If not - you don't need it. Why it generated it automatically? It made assumption that you will be using Simulation from side of factory. like ```java
Factory factory = rep.getFactoryById(id);
SimulationEntity se = factory.getSimulationEntity()
se.doSomething();// thi object is already set as field in factory entity, you don't need to fetch it manually

#

@ManyToOne means that many factories have reference to the same simulation

#

on side of SimulationEntity you should have something like ```java
@OneToMany(mappedBy="simulationId")
List<Factory> factories;

#

so if you will get a SimulationEntity object, you will be able to get list of factory objects that use this simulation

merry fractal
tall pivot
merry fractal
small cradleBOT