Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

mapping a class multiple times / persisting Maps #5539

gavinking started this conversation in Design Proposals
Discussion options

From https://hibernate.atlassian.net/browse/HHH-15698:

We’ve deprecated the hbm.xml format without providing any replacement way to map a class with two different entity names. We have jumped through hoops in our APIs and internal implementation to support this usage.

Actually, just how deprecated is it really? Sure, we don't really document it, but nor do we document orm.xml. The documentation is basically completely silent on the subject of XML-based mappings and you're supposed to do them.

There's no straightforward way out of this, either:

  • we un-deprecate hbm.xml, since it's the only way to specify an explicit entity name,
  • introduce a brand new XML mapping format, derived from orm.xml, but with the ability to specify entity names for entities and associations, or
  • we deprecate the remaining methods of Session that accept a string entityName, since they’re only useful with the deprecated hbm.xml mapping format.

Note that it would not help to introduce new annotations, since you can’t define multiple mappings for a single class in annotations. (Nor you can you define mappings for Maps.)

So what we’re contemplating here is losing:

  1. the ability to map a class multiple times with different entity names, and
  2. the ability to persist a Map.
You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

As far as I understand, the <entity/> tag supports specifying a class and name attribute, so mapping the same class under a different name should be doable. The association mappings in XML also don't seem to require interpreting the explicit attribute target-entity as class, so maybe we can already do what you are looking for. Users would simply have to use the class java.util.Map since the class attribute of <entity/> is required.

Steve already started working on orm.xml extensions, so if we want further extensions, we can put that there.

You must be logged in to vote
2 replies
Comment options

gavinking Nov 10, 2022
Maintainer Author

Yeah that's what I thought initially (it's what I tried writing) but it's certainly not how we're interpreting these things right now.

But perhaps we could change it so that name is interpreted as a real entity name, and not just as an abbreviation in the query language. (It's not quite as simple as that, but probably we could make it work without too much breakage.)

So yeah, maybe you're right.

Steve already started working on orm.xml extensions, so if we want further extensions, we can put that there.

Yeah, yeah, what I came back here to say was: isn't this something we could handle with XML namespaces? I had forgotten about them.

Comment options

I'm not understanding the thought process with namespace, so hard to say. IIUC you are asking whether we can "replace" certain XSD types (<entity/>, etc) with our own. The answer is no. Its a rabbit hole. The only way to refer to our custom <entity/> type is to also replace its container (<entity-mappings/>), and on and on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /