This worked and was relatively painless. It has been suggested that this is a better logging mechanism to use than Log4J.
How to configure logging in Hibernate – Logback
http://www.mkyong.com/hibernate/how-to-configure-logging-in-hibernate-logback/
Wednesday, June 26, 2013
Java; Hibernate; apply prefix to database tables
My current project uses two collections of tables. One set is maintained by one application. The other set by another. I won't explain why they are not using separate databases so that the same table names may be used. I admit, that would be a better solution. Or even using different schemas. Instead, one collection is differentiated by a table prefix and the other doesn't have one.
How can this be accomplished with minimal impact to the source code so that common libraries may be shared between the two applications? A NamingStrategy class did the job nicely.
Hibernate Community Documentation: Configuration: 3.6. Implementing a NamingStrategy
http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/session-configuration.html#configuration-namingstrategy
The only difference in setting up the SessionFactory for each application was to add one line in the Configuration setup. Not very invasive and I have been able to reuse a lot of code, including all my DAOs and Hibernate annotations.
When setting up Hibernate, I pretty much followed the example listed under 'Create Application Class'. I didn't need to include lib/ejb3-persistence.jar (listed as required under 'Environment Setup for Hibernate Annotation') as it appears to be included in the Maven resources listed in its associated pom.xml file.
How can this be accomplished with minimal impact to the source code so that common libraries may be shared between the two applications? A NamingStrategy class did the job nicely.
http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/session-configuration.html#configuration-namingstrategy
The only difference in setting up the SessionFactory for each application was to add one line in the Configuration setup. Not very invasive and I have been able to reuse a lot of code, including all my DAOs and Hibernate annotations.
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.1.4.Final</version> </dependency> <dependency> <groupId>org.hibernate.common</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>4.0.1.Final</version> </dependency>
Additional Resources
- http://www.petrikainulainen.net/programming/tips-and-tricks/implementing-a-custom-namingstrategy-with-hibernate/
- Google search for hibernate and namingstrategy
- http://stackoverflow.com/questions/5050538/hibernate-improvednamingstrategy-overrides-table-name-in-entity
- http://stackoverflow.com/questions/4313095/jpa-hibernate-and-custom-table-prefixes
Java; unit testing; available tests
JUnit: A set of assertion methods useful for writing tests
http://junit.sourceforge.net/javadoc/org/junit/Assert.html
http://junit.sourceforge.net/javadoc/org/junit/Assert.html
Java; iterating through and Iterable collection
Performance: Iterating through a List in Java
http://stackoverflow.com/questions/2642004/performance-iterating-through-a-list-in-java
http://stackoverflow.com/questions/2642004/performance-iterating-through-a-list-in-java
Java; basic I/O, including file handling
The Java Tutorials: Lesson: Basic I/O
http://docs.oracle.com/javase/tutorial/essential/io/
http://docs.oracle.com/javase/tutorial/essential/io/
Java; parsing dates
Most of the time, this works just fine:
how to create Date object from String value
http://stackoverflow.com/questions/15760248/how-to-create-date-object-from-string-value
This also has merit and I love how short and concise it is:

Larry's Road to J2EE: How to convert String to XMLGregorianCalendar
http://larryjjcao.blogspot.com/2012/04/how-to-convert-string-to.html
The Date class seems to be frowned upon for direct use since it is riddle with deprecation warnings (at least for creating dates using the class's constructors). It instead seems more favorable using Calendar or GregorianCalendar.
how to create Date object from String value
http://stackoverflow.com/questions/15760248/how-to-create-date-object-from-string-value
This also has merit and I love how short and concise it is:
Larry's Road to J2EE: How to convert String to XMLGregorianCalendar
http://larryjjcao.blogspot.com/2012/04/how-to-convert-string-to.html
The Date class seems to be frowned upon for direct use since it is riddle with deprecation warnings (at least for creating dates using the class's constructors). It instead seems more favorable using Calendar or GregorianCalendar.
Java; parse XML using XPath
Nice XML parser I found that uses XPath to extract data. I'm using it in my unit testing.
• Select XML nodes using XPath and a single line of Java code
https://github.com/gioele/xpathapi-jaxp
E.g.,
What are other Java resources that also use XPath to isolate and extract data?
If you don't want to use XPath for data extraction, you could always use another library, like the DOM Parser.
• Select XML nodes using XPath and a single line of Java code
https://github.com/gioele/xpathapi-jaxp
E.g.,
List<Node> bestFriends = XPathAPI.selectListOfNodes(doc, "//friend[@status='best']");
doc can be an instance of Document or Node. This should help keep XPath references shorter since they can be relative to a Node instead of the top level Document.What are other Java resources that also use XPath to isolate and extract data?
If you don't want to use XPath for data extraction, you could always use another library, like the DOM Parser.
Subscribe to:
Posts (Atom)