These are chat archives for hibernate/hibernate-orm

15th
Aug 2017
Al Grant
@bigalnz
Aug 15 2017 07:34
Trying to follow along with this tutorial : https://www.thoughts-on-java.org/many-relationships-additional-properties/ but why has he got two classes called BookPublisher?
ryan2049
@ryan2049
Aug 15 2017 08:08
The file is really called BookPublisherId look at the bottom of the frame
Al Grant
@bigalnz
Aug 15 2017 08:09
Yes I see that too - so its ok to have two class names the same in different files in the same project?
ryan2049
@ryan2049
Aug 15 2017 08:13
If they're in different packages, but I think it was a mistake
Al Grant
@bigalnz
Aug 15 2017 08:13
what should it be?
ryan2049
@ryan2049
Aug 15 2017 08:14
The @Embeddable can stand on it's own. No need to bury it in an inner static class
Al Grant
@bigalnz
Aug 15 2017 08:18
If I change my file name to EpisodePersonId it complains that the class must be contained in a file of the same name (my class is EpisodePerson
ryan2049
@ryan2049
Aug 15 2017 08:18
Correct
Al Grant
@bigalnz
Aug 15 2017 08:19
But he has class in files whose name doesnt match?
ryan2049
@ryan2049
Aug 15 2017 08:21
It was a mistake I'm sure
Al Grant
@bigalnz
Aug 15 2017 08:22
Maybe - his linked github project has the same error then
But if I call my class (using his example) BookPublisherId then I have another inner class of BookPublisherId I now have two classes in the same file with the same name - thats not allowed either
ryan2049
@ryan2049
Aug 15 2017 08:24
Please reread what I said
Al Grant
@bigalnz
Aug 15 2017 08:25
Ok, I have reread it, not any clearer on how to go about this than before?
ryan2049
@ryan2049
Aug 15 2017 08:26
Get rid of the surrounding class definition and drop the static modifier
Al Grant
@bigalnz
Aug 15 2017 08:28
Yeah ok...that stops the IDE complaints
@Entity
@Embeddable
public class EpisodePersonId implements Serializable {
    @Column(name = "fk_episode")
    protected Long episodeId;
ryan2049
@ryan2049
Aug 15 2017 08:29
Drop the @Entity
Al Grant
@bigalnz
Aug 15 2017 08:30
OK
Its going to take me some time to work out this all wires together - looks complicated
ryan2049
@ryan2049
Aug 15 2017 08:35
An @Embeddable class is considered a component
Typically a component allows you subclass columns on the same table
Al Grant
@bigalnz
Aug 15 2017 08:44
OK
So I have
Copied his example but have a few errors highlited by my IDE
@Column
@Enumerated(EnumType.STRING)
private EpisodeRole episodeRole;
EpisodeRole can not resolve?
ryan2049
@ryan2049
Aug 15 2017 08:46
In this case it's an @EmbeddedId so it takes what's defined and uses it as a composite id
?
Al Grant
@bigalnz
Aug 15 2017 08:46
?
ryan2049
@ryan2049
Aug 15 2017 08:47
Is that a class you have defined?
Chris Cranford
@Naros
Aug 15 2017 13:03
@bigalnz I wouldn't worry so much about the file names shown on github for his example. Thorben was basically using a gist to host pieces of code for that blog and nothing else. What I believe he was trying to illustrate is that an @Embeddable can be an inner class of the entity, which isn't an unusual practice for embedded identifiers. But it doesn't have to be done that way.
What Ryan was trying to explain was that if you take that @Embeddable and move it to its own class & compilation unit, it will work the same. In fact, if your project uses static metamodel generation, that is a requirement as the static metamodel generation process doesn't work with inner static classes.
What Thorben was illustrating was a concept, not necessarily a fully-functioning project of code.
Al Grant
@bigalnz
Aug 15 2017 18:48
@Naros @ryan2049 if you have a look now I have enum the EpisodeRoles in EpisodePerson