[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6218) Bind @IdClass

Hardy Ferentschik (JIRA) noreply at atlassian.com
Thu May 26 11:31:25 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6218?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=42420#action_42420 ] 

Hardy Ferentschik commented on HHH-6218:
----------------------------------------

from irc
{quote}
hardy_: atm we only implemented a single/simple id
[4:05pm] sebersole: @IdClass... fune
[4:05pm] sebersole: fun
[4:05pm] hardy_: so if we would see how this is supposed to work that would be a great help
[4:05pm] hardy_: i haven't thought about @MapsId yet
[4:05pm] sebersole: well i have not thought through @IdClass at all
[4:05pm] sebersole: right, nor that one
[4:06pm] smarlow: sebersole:  I changed my mind about enhancing Scanner, its not worth it.
[4:06pm] sebersole: smarlow: kk
[4:06pm] hardy_: doesn't hbm support multiple ids?
[4:06pm] sebersole: yep
[4:06pm] sebersole: you mean multiple attributes
[4:07pm] hardy_: yes
[4:07pm] sebersole: ?
[4:07pm] sebersole: then yes
[4:07pm] hardy_: an entity id composed of multiple attributes
[4:07pm] sebersole: we call that an embedded composite id
[4:07pm] sebersole: confusing huh 
[4:07pm] hardy_: right
[4:07pm] sebersole: but we used that term first
[4:07pm] hardy_: composite if is the term I used/heard as well
[4:07pm] sebersole: we could name it somethign else this go around to avoid confusion
[4:08pm] sebersole: well composite is a bigger concept
[4:08pm] sebersole: its any tupled id
[4:08pm] sebersole: not sure a better term for what hibernate calls embedded comp id
[4:09pm] sebersole: thats the main problem with changing the term
[4:09pm] hardy_: so mapping wise is there a big difference between @EmbeddedId and @IdClass?
[4:09pm] hardy_: i am fine w/ it
[4:09pm] hardy_: even tough it might be a little confusing
[4:09pm] sebersole: well the jpa notion of embedded and hibernate's are totally different
[4:10pm] hardy_: it's easy to point out confusing class/concept names, but much harder to have a better alternative
[4:10pm] sebersole: @EmbeddedId is naming a single attribute (component) to act as the id
[4:10pm] hardy_: right
[4:10pm] sebersole: the hibernate "embedded" is naming multiple attributes (on the entity!) to act as id
[4:11pm] sebersole: with or without an @IdClass
[4:11pm] hardy_: ok
[4:12pm] sebersole: yes there needs to be a difference in how we handle @EmbeddedId and @IdClass
[4:13pm] sebersole: maybe good to start splitting the notions these things cover
[4:13pm] sebersole: today we just have "id" as an attribute and the "generator"
[4:14pm] sebersole: then we sort of bolted on this notion of a "id mapper"
[4:15pm] sebersole: like i said i have not thought about this too much before, so lot of this is veeeeeerrrrrry prelim ideas
[4:15pm] sebersole: as in i am just brain storming on the spot 
[4:16pm] sebersole: but maybe we have (1) notion of the attribute (we do already, o.h.metamodel.domain)
[4:16pm] sebersole: (2) notion of its gen strategy
[4:17pm] sebersole: (3) notion of any "alternate representations"
[4:17pm] namemon left the chat room. (Quit: namemon)
[4:18pm] sebersole: change (1) ->
[4:18pm] sebersole: (1) its domain representation in general (might be multiple attributes)
[4:19pm] sebersole: of source we also need (1.a) relational rep
[4:19pm] sebersole: of course...
[4:19pm] hardy_: right
[4:21pm] hardy_: if you don't have something like a IdClass, how to you handle a find then?
[4:21pm] hardy_: if it wouldn't be for that ther IdClass has not much use right?
[4:21pm] sebersole: you create an instance of the entity and populate its id values
[4:21pm] sebersole: and pass that in as the id
[4:21pm] hardy_: and is this what the mentioned mapper does
[4:21pm] adamw1pl joined the chat room.
[4:22pm] sebersole: mapper does many things
[4:22pm] sebersole: trying to find that code actually since its been a long time since i looked at it
[4:22pm] hardy_: i was about to ask you for the class name
[4:22pm] hardy_: there is a IdMapper class, but that's in envers 
[4:23pm] hardy_: i figure it must be somewhere else
[4:23pm] sebersole: its not a class iirc
[4:24pm] sannegrinovero left the chat room. (Read error: Operation timed out)
[4:26pm] sebersole: hardy_: ok... its handled in org.hibernate.tuple.entity.AbstractEntityTuplizer
[4:27pm] sebersole: and comes initially from org.hibernate.mapping.PersistentClass#getIdentifierMapper
[4:28pm] sebersole: basically it defines a component
[4:28pm] sebersole: literally, a org.hibernate.mapping.Component
[4:28pm] hardy_: ok
[4:29pm] sebersole: so @IdClass -> org.hibernate.mapping.Component
[4:29pm] sebersole: which then becomes the basis of this "mapper"
[4:29pm] sebersole: later i did add this notion of org.hibernate.tuple.entity.AbstractEntityTuplizer.MappedIdentifierValueMarshaller
[4:29pm] jpav joined the chat room.
[4:30pm] sebersole: "mapped id" is the name we gave @IdClass
[4:30pm] sebersole: internally
[4:30pm] hardy_: IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller - ha ha
[4:30pm] sebersole: again, we can change (and prolly should) these terms
[4:30pm] sebersole:
[4:31pm] hardy_: this one we should keep
[4:31pm] hardy_: it's a classic 
[4:31pm] hardy_: i need to browse this code a little to get a feeling what's going on
[4:31pm] sebersole: there is another like that
[4:31pm] sebersole: me too! 
[4:31pm] sebersole: been long time
[4:32pm] hardy_: if we can simplify this it would be awesome
[4:32pm] sebersole: basically the mapper defines a component for the class named by @IdClass
[4:32pm] sebersole: well its pretty "simple" i think now looking at it
[4:32pm] sebersole: we just need to encapsulate it better maybe
[4:32pm] sebersole: its does leak and spread out a bit
[4:33pm] sebersole: so basically we have:
[4:33pm] sebersole: 1) the mapper defines a "virtual" component for the class named by @IdClass
[4:34pm] sebersole: 2) MappedIdentifierValueMarshaller knows how to marshall those "alternate representations" i mentioned before to the actual internal rep
[4:34pm] sebersole: @IdClass being one "alternate representations"
[4:34pm] sebersole: @MapsId being another
[4:34pm] hardy_: ok
[4:35pm] hardy_: so from a binding point of view what do we have to create?
[4:35pm] sebersole: well for @IdClass we need component or something sim
[4:36pm] sebersole: of course for @EmbeddedId we have component
[4:36pm] hardy_: right
[4:37pm] sebersole: i think we should delay the "interpretation" to MappedIdentifierValueMarshaller (or multiple) until later
[4:37pm] sebersole: meaning not in the binding
[4:37pm] adamw1pl left the chat room. (Quit: adamw1pl)
[4:37pm] sebersole: unless there is pertinent info in the meta
[4:37pm] sebersole: that we currently do not capture
[4:38pm] sebersole: i think for @IdClass what i said is fine
[4:38pm] hardy_: ok
[4:38pm] sebersole: no clue mostly about @MapsId
[4:38pm] sebersole: that stuff boggles my mind whenever i look 
[4:38pm] sebersole: in the spec i mean
[4:38pm] hardy_: i need to read the spec again. i remember I tried to implement this once, but in the end Emmanuel had to help
[4:39pm] hardy_: The MapsId annotation is used to designate a ManyToOne or OneToOne relationship attribute that provides the mapping for an EmbeddedId primary key, an attribute within an EmbeddedId primary key, or a simple primary key of the parent entity.
[4:40pm] sebersole: hardy_: yeah i get the general principle
[4:40pm] sebersole: it lets you ask for an entity with another entity as part of its key by just that other entity's pk
[4:41pm] sebersole: i get that
[4:41pm] sebersole: its just amazingly complicated
[4:41pm] hardy_: i like your explanation better
[4:41pm] sebersole: more succinct 
[4:42pm] hardy_: jupp
[4:42pm] sebersole: @IdClass and @MapsId are all about load process
[4:45pm] galderz left the chat room. (Quit: Leaving.)
[4:45pm] sebersole: hardy_: in looking through the code some more maybe we really just need better vocab around this stuff
[4:46pm] sebersole: so...
[4:46pm] sebersole: what hibernate calls embedded comp id...
[4:46pm] hardy_: sure, you know this better than I do
[4:46pm] sebersole: i also sometimes call a "flat" comp id
[4:47pm] sebersole: so maybe we can change that terminology to avoid confusion with the jpa term
[4:47pm] sebersole: flat/flattened
[4:48pm] sebersole: does that give you good visual?
[4:48pm] hardy_: why flattened?
[4:48pm] hardy_: i try to see "flat" part
[4:49pm] sebersole: just different word form of flat
[4:49pm] hardy_: flat / flattened
[4:49pm] hardy_: in both cases I a missing where you are coming from
[4:49pm] sebersole: so then thats obviously not a good term 
[4:50pm] sebersole: a composite id via an actual component is aggregated
[4:50pm] sebersole: the id values aggregated into the component
[4:50pm] sebersole: but in this case we talking about the values are flattened on to the entity
[4:50pm] hardy_: ahhh
[4:51pm] hardy_: what's about something like direct comp id
[4:51pm] sebersole: wdym with direct?
[4:52pm] hardy_: the values are directly on the entity
[4:53pm] hardy_: i thought more of a opposite to embedded i guess
[4:53pm] sebersole: well tbh i think embedded as jpa uses it is an awful term
[4:55pm] hardy_: I think it makes sense for @Embeddable and @Embedded. for ids it gets a little more complicated
[4:56pm] hardy_: if you think flat is good that works for me
[4:56pm] hardy_: better than embedded comp id, because that's really conflicting w/ jpa terminology
[4:57pm] sebersole: even there i think its a bad term
[4:57pm] sebersole: its almost exactly the opposite of what the english for embedded means
[4:58pm] sebersole: if you look at it from the individual values
[4:58pm] sebersole: if you look at it from the class, ok maybe, but still not InLove with it
[4:58pm] sebersole: not the best choice of terms imho
[4:59pm] hardy_: good that I am not native English speaking and good that I have no BA in English, seems to make my life easier
[4:59pm] sebersole: haha trudat
[5:00pm] hardy_: btw, I tend to definitely argue more from a class perspective
[5:00pm] sebersole: well but even then...
[5:00pm] hardy_: I think JPA tries to generally look at things from this angle
[5:00pm] sebersole: where else in OO do you ever talk about a class being embedded in another?
[5:01pm] sebersole: this is composition
[5:01pm] sebersole: in modeling terms
[5:01pm] hardy_: so would be for a single @Component annotation
[5:02pm] sebersole: or @Composition
[5:02pm] sebersole: yeah, something like that
[5:03pm] hardy_: well, I would go for @Component, unfortunately I don't think we can change this now 
[5:03pm] sebersole: hardy_: nope, but
[5:03pm] sebersole: does not mean we have to follow those names internally
[5:04pm] hardy_: true
[5:04pm] sebersole: would much rather have good names internally
[5:04pm] sebersole: as it makes reading code soooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo much easier
[5:04pm] sebersole: you know, stuff like IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller
[5:04pm] sebersole: haha
[5:04pm] hardy_: he he
[5:14pm] sebersole: hardy_: that give you what you need?
[5:16pm] stliu joined the chat room.
[5:27pm] hardy_: stliu: I just discussed w/ sebersole the id stuff
[5:27pm] stliu: hardy_, so?
[5:28pm] hardy_: I will attach the log to the jira issue
[5:28pm] stliu: okay
{quote}

> Bind @IdClass
> -------------
>
>                 Key: HHH-6218
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6218
>             Project: Hibernate Core
>          Issue Type: Sub-task
>          Components: metamodel
>            Reporter: Hardy Ferentschik
>            Assignee: Strong Liu
>             Fix For: 4.0.0.Beta1
>
>


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list