|
[
Permalink
| « Hide
]
Kalle Korhonen added a comment - 11/Jul/07 03:05 AM
I still fail to see any benefit in this annotation. You certainly don't have maintain seeded entities in xml - it's simply one way to seed the database. I have no idea what "having to articulate other dependent annotations attributes to alter schema logic" means. ASOs are not connected to persistent entities. If you just want a single entity, make it's id property always return a static value. If you want a true singleton, implement a static class/method that'll always return a single instance, with values populated either from database using getInstance, XML or in Spring configuration.
Decided to seed an entity which initially has ID=1
Then make it an ASO and load the ASO off of ID=1 The ASO itself is prevented from replicating itself by making an one of the property fields unique. Wanted to offer the actual solution here... a singleton ASO loaded at bootstrap. Not my idea of a pure singleton... but you get the idea.
The solution is based on a pojo named AdminLayout (not provided but you can use your own). ApplicationContext-seedData.XML AdminLayoutFactory.JAVA public Object createStateObject() { return (AdminLayout) layoutDao.loadSingleton(); }public void setLayoutDao(AdminLayoutDAO adminLayoutDao) { this.layoutDao = adminLayoutDao; }} AdminLayoutDAO.JAVA AdminLayout layout = null; public AdminLayout loadSingleton() throws DataAccessException { DetachedCriteria criteria = DetachedCriteria.forClass(AdminLayout.class); criteria.add(Restrictions.eq("id", 1)); layout = persistenceService.getInstance(AdminLayout.class, criteria); return layout; }public AdminLayout getLayout() { return layout; }public void setLayout(AdminLayout layout) { this.layout = layout; }public HibernatePersistenceService getPersistenceService() { return persistenceService; }public void setPersistenceService(HibernatePersistenceService persistenceService) { this.persistenceService = persistenceService; }} <service-point id="adminLayoutFactory" interface="org.apache.tapestry.engine.state.StateObjectFactory">
<invoke-factory> <construct class="org.trails.demo.service.AdminLayoutFactory"> <set-object property="layoutDao" value="spring:adminLayoutDAO"/> </construct> </invoke-factory> </service-point> |
|||||||||||||||||||||||||||||||||||||||||||||||