Migration from Oracle to MySQL running on Amazon RDS
The final insult…
Hibernate foreign-key collections and database best practice
I came across the following situation having noticed we were not enforcing database NOT NULL column constraints, even though all column entries were non-null. This is not best-practice from a database perspective and so I thought I’d look into it.
So, I have 2 tables, ENQUIRY and ELEMENT with a One-to-Many relationship such that an Enquiry has many Elements. And I wanted to enforce the NOT NULL constraint on foreign key column ELEMENT.ENQUIRY_ID. This relationship looks like so when modeling the Enquiry object with Hibernate:
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "ENQUIRY_ID", referencedColumnName = "ID")
private Set elements = new HashSet();
When I enforced the NOT NULL constraint at the database level I received the following stacktrace however:
Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("ELEMENT"."ENQUIRY_ID")
So Hibernate is obviously persisting the collection of elements before the parent enquiry and then going back and doing an UPDATE on the foreign key field afterwards (so INSERT collection items with NULL foreign key, INSERT parent, UPDATE collection item foreign keys) as it doesn’t realise the foreign key column will always be non-null.
You must explicitly tell Hibernate that the foreign key column is NOT NULL. It can then persist the parent enquiry first followed by the collection items. To do this, add the following clause to the @JoinColumn annotation:
@JoinColumn(name = "ENQUIRY_ID", referencedColumnName = "ID", nullable = false)
This way, not only are you ensuring database best-practice, but Hibernate will also have to issue less statements (so INSERT parent, INSERT collection items) which should be a more efficient transaction statement.
The javax.persistence.JoinColumn API only states that the nullable clause indicates whether the foreign key column is nullable but nowhere could I find how this nuance affects Hibernate and the queries it issues – it’s probably out there someplace but I hope this post can help anyone with a similar problem.
Thanks to axtavt on stackoverflow for pointing out the obvious!
Mocking static method dependencies
Good article on refactoring “static cling“, have used this several times now:
@Service("securityContextRepository")
public final class SecurityContextRepositoryImpl implements SecurityContextRepository {
@Override public SecurityContext getSecurityContext() {
// Spring framework dependency that I rely on but do not wish to test directly
return SecurityContextHolder.getContext();
}
}
I can now mock the SecurityContextRepository implementation that is injected into my test cases and remove the reliance on a static method call.
Git revert a mistaken commit
You have 2 commits staged, and you want to keep the latest but revert the first. Easy when you know how:
git revert HEAD^
RESTful system design
A useful resource (see what I did there?) showing starting point and evolving maturity when designing RESTful systems, courtesy of the ubiquitous Martin Fowler.
Oracle 11g UCP with Tomcat
Ensure you have the below tnsnames.ora file in TNS_ADMIN so as to connect to the server from client using connect string: sqlplus <username>@xyz
xyz = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (PORT = <port>) (HOST = <server_name>) ) (CONNECT_DATA = (SID = <SID>)) )
tomcat/conf/server.xml file:<GlobalNamingResources>
<Resource name="jdbc/<pool_jndi_name>" auth="Container" url="jdbc:oracle:thin:@<server_name>:<port>:<SID>" user="<username>" password="<password>" factory="oracle.ucp.jdbc.PoolDataSourceImpl" type="oracle.ucp.jdbc.PoolDataSource" connectionFactoryClassName="oracle.jdbc.pool.OracleDataSource" connectionPoolName="<pool_name>" connectionWaitTimeout="30" minPoolSize="5" maxPoolSize="25" inactiveConnectionTimeout="20" timeoutCheckInterval="60" validateConnectionOnBorrow="true" sqlForValidateConnection="SELECT 1 FROM DUAL" />
...ucp.jar to tomcat/libs directory.
Dozer examples
Best place to find Dozer example mapping files is in the source bundle under test/resources. Most other examples out there are pretty basic and won’t help you if you want to do something more complex…
Google Apps observations
After experimenting and persevering with Google Apps in a corporate environment I would say the following are the headline issues we have experienced:
Positives:
- Fantastic cost/effort reduction over homegrown or outsourced alternatives
- Simple setup and good online documentation and usability
Negatives:
- Lack of full product features in Google Docs versus MS Office
- Security features not entirely sufficient for a corporate environment
In general, for the cost, speed and effort with which you can set up a functioning environment I would say it’s definitely worth at least making sure you positively rule out Google Apps as an option for your corporate IT infrastructure.
The major issues we have found that might count against Google would be the inability to restrict usage to a certain IP range (i.e. the office) and poor Docs interoperability with MS Office. Until these are resolved corporate users will be slow on the uptake.
I think it’s a reasonable assumption that the products will improve rapidly – but I have found a lot of people with similar observations and no indication from Google that the security issues at least are being tackled!
Software Architecture Document
Really helpful Software Architecture Document guidelines. Worth a shout to codingthearchitecture.com, I like their “style” very much…
Agile Management
I have recently been involved with a project that had a great development team – project manager, BA, server-side and UI developers and a QA team – all co-located and pulling merrily and effectively along together towards the same objectives.
Whilst we undertook some pretty serious refactoring efforts as the Product Owner (rightly) demanded a change of direction and focus, there were numerous issues that arose as senior managers who had little knowledge or understanding of the project – or possibly more importantly Agile – came under increasing pressure to “do something” as the timelines wore on due to the change of direction.
Kelly Waters’ post on why Agile must be adopted and understood from the top-down pretty succinctly sums up many of the challenges we faced, particularly around stakeholder management and expectations.
As I’ve mentioned before in response to a similar post by Mark Schumann, it’s a shame and a surprise to me that those who do not understand or are not involved directly in an Agile project, but are nonetheless in positions of influence and supposed control, cannot do a little more to understand what is in essence a fairly simple, and I doubt particularly uncommon, scenario.
Agile CTO
- tech_startup: Puppet certificate issues http://t.co/oM6y53rx 4 days ago
- have invented a new UNIX tool for cutting the grass: sudo chmown aeells:aeells squid.conf.bkp sudo: chmown: command not found 5 days ago
- I support #wikipediablackout Show your support here http://t.co/UFN8O0gk 2 weeks ago
- reasonable man adapts himself to world; unreasonable man tries to adapt world to himself; => all progress depends on unreasonable man. 3 weeks ago
- @blinkdesign we could do that too!!!!? ;o) in reply to blinkdesign 3 weeks ago
- @blinkdesign we could do something similar on our tech blog maybe... in reply to blinkdesign 3 weeks ago
- ".....in all things, the supreme excellence is simplicity." Henry Wadsworth Longfellow 3 weeks ago
- good day bootstrapping #tomcat #memcached to #aws server via #puppet - looking forward to provisioning entire production replica in minutes! 3 weeks ago
- great (practical) example of how to do #continousdeployment and branching within teams http://t.co/ceeyvD0h courtesy @chacon @domfarr 2012-01-05
- hi @ruv, mind if i ask how you came by that statistic? cheers! in reply to ruv 2012-01-02
- More updates...



