Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Pojos same table Hibernate

I have a table that is something like this:

╔════════════╗
║ table_test ║
╠════════════╣
║ id         ║
║ type       ║
║ message    ║
║ param_x    ║
║ param_y    ║
║ param_z    ║
║ result_a   ║
║ result_b   ║
║ result_c   ║
╚════════════╝

So it's a test that have some parameters and have some results. I don't have a table with the parameters because they aren't pre-defined.

So I want to map this to 3 classes: Test, Paramters and Results.

How can I map this in Hibernate? How Could I, for example, Get the Test and have a Parameters object with the database info ?

Patameters and Result will be fields of Test class.

like image 595
lcguida Avatar asked May 25 '26 16:05

lcguida


1 Answers

Use an entity class (Test) and two embedded object classes (Parameters and Results), as described in the Hibernate documentation

@Entity
public class Test
    @Embedded
    private Parameters parameters;

    @Embedded
    private Results results;
}

@Embeddable
public class Parameters {
    ...
}

@Embeddable
public class Results {
    ...
}
like image 152
JB Nizet Avatar answered May 28 '26 08:05

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!