-
1. Re: How to retrieve the value of a
dmlloyd Oct 23, 2009 9:21 AM (in response to epbernard)So the default value of the field depends on the JPA spec in force? How is that differentiated? Through the namespace?
-
2. Re: How to retrieve the value of a
aloubyansky Oct 23, 2009 9:50 AM (in response to epbernard)Use controls presence. If use="required" the attribute must appear in the XML.
Fixed is a value constraint. If the attribute is present and different from the fixed value the parsing will fail.
All this stuff is handled by the underlying xml parser, which is xerces SAX in our case. Xerces will include fixed and default attributes into org.xml.sax.Attributes only if schema validation is enabled.
In XB you can do that by unmarshaller.setSchemaValidation(true); -
3. Re: How to retrieve the value of a
epbernard Oct 23, 2009 10:06 AM (in response to epbernard)"david.lloyd@jboss.com" wrote:
So the default value of the field depends on the JPA spec in force? How is that differentiated? Through the namespace?
Different version of the xsd, there is also a version attribute on the schema (unrelated though in theory) -
4. Re: How to retrieve the value of a
dmlloyd Oct 23, 2009 10:15 AM (in response to epbernard)I guess Alexey nailed it. Anyway it's unlikely we'd ever turn on validation due to perf. reasons.
My analysis of handing this kind of situation (two very similar but not identical namespaces with JBossXB or JAXB in general) came to the conclusion that you can't really do it cleanly without having completely separate object models, which of course is a ton of redundancy. Maybe there's some way you can hack it into telling you what namespace was parsed? Setting it as a property on your root element or something? -
5. Re: How to retrieve the value of a
aloubyansky Oct 23, 2009 10:18 AM (in response to epbernard)We could create an annotation for this.
-
6. Re: How to retrieve the value of a
epbernard Oct 23, 2009 10:20 AM (in response to epbernard)"alex.loubyansky@jboss.com" wrote:
Use controls presence. If use="required" the attribute must appear in the XML.
Fixed is a value constraint. If the attribute is present and different from the fixed value the parsing will fail.
You sure? My schema parsing is failing when I add unexpected elements (blah) but they pass if I don't set version.
Even worse, if I set version, then it failsCaused by: org.xml.sax.SAXException: cvc-complex-type.3.2.2: Attribute 'version' is not allowed to appear in element 'persistence-unit'
All this stuff is handled by the underlying xml parser, which is xerces SAX in our case. Xerces will include fixed and default attributes into org.xml.sax.Attributes only if schema validation is enabled.
In XB you can do that by unmarshaller.setSchemaValidation(true);
It's for JBoss Metadata's JPA parsing. Do you know the piece of code that set the unmarshaller? -
7. Re: How to retrieve the value of a
aloubyansky Oct 23, 2009 10:35 AM (in response to epbernard)Yes, I am sure. I have tested it.
The unmarshaller is initialized (depends on how you write your tests, of course, but for many...) in JBossXBTestDelegate which is in tests of metadata/common. -
8. Re: How to retrieve the value of a
aloubyansky Oct 23, 2009 10:37 AM (in response to epbernard)PS: XB also does some limited validation especially for elements in a sequence. It's not a feature in itself but a side effect of the implementation. So, maybe it was the XB error.
-
9. Re: How to retrieve the value of a
epbernard Oct 23, 2009 10:49 AM (in response to epbernard)"alex.loubyansky@jboss.com" wrote:
The unmarshaller is initialized (depends on how you write your tests, of course, but for many...) in JBossXBTestDelegate which is in tests of metadata/common.
I mean how do I make sure my PersistenceMetadata and PersistenceUnitMetadata are parsed with validation enabled in the grand scheme of JBoss AS. Having passing unit tests while the core product fails will do me no good :) -
10. Re: How to retrieve the value of a
aloubyansky Oct 23, 2009 11:02 AM (in response to epbernard)Each parsing deployer (that extends https://anonsvn.jboss.org/repos/jbossas/projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java) has property useSchemaValidation.
You can actually see it (set to false or commented out ;) ) in ejb-deployer-jboss-beans.xml and ear-deployer-jboss-beans.xml -
11. Re: How to retrieve the value of a
epbernard Oct 23, 2009 11:24 AM (in response to epbernard)Seems I am out of luck.
PersistenceUnitDeployer extends AbstractSimpleRealDeployer extends AbstractRealDeployer extends AbstractDeployer
So my chain does not seem to extend JBossXBDeployer.java -
12. Re: How to retrieve the value of a
emuckenhuber Oct 23, 2009 12:45 PM (in response to epbernard)As far as i can remember there is a PersistenceParsingDeployer extending JBossXBDeployer, doing the actual parsing of the persistence.xml.
-
13. Re: How to retrieve the value of a
aloubyansky Oct 23, 2009 3:25 PM (in response to epbernard)Yes
<bean name="PersistenceParsingDeployer" class="org.jboss.jpa.deployers.PersistenceParsingDeployer"/>