[JBoss Tools (users)] - Re: Launch Files: Real control of Seam-Gen
by max.andersen@jboss.com
"luxspes" wrote :
| We (in my project) have heavily modified and enhanced the functionality of seam-gen, but I think we are hitting a hard limit: we can not say "do not generate the EntityEdit.xhtml" because that is read-only. No matter what we do, all the *.ftl templates get called for all the our entites.
|
Yes, that is the default behavior.
anonymous wrote :
| We use JBossTools 2.1.1 and store our seam-gen configurations in Eclipse .launch files (and call them using the Code Generation Launcher).
|
Nice to see the .launch saving feature being used as intended (sharing of custom code generations)
anonymous wrote :
| As you can see, the exporter configuration for EntityEdit.xhtml is very different, and one of themain differences is that it has a :
|
|
| | <mapEntry key="for_each" value="entity" />
| |
|
| now, i would like to extend this mechanism to make it possible to generate the EntityEdit.xhtml only for... for example non-readonly entities (or any other criteria that I choose):
|
| <mapEntry key="for_each" value="readonly-entity" />
| |
|
For the moment for_each is hardcoded to only understand the Configuration notions of Pojo's (e.g. entity and component)
I have considered adding table, foreign_key etc. too since they are "concepts" in the Configuration API but it felt wrong to do so (entities and database level concepts being mixed up).
What I have considered was to add some way to put an expression in for_each that could be iterated but that haven't been done yet (contributions welcome! :)
That being said there is way to do what you want - read below.
anonymous wrote :
| (And then create my own custom @ReadOnlyEntity annotation to control generation)
|
Sounds doable - you could also use the mutable attribute of Hibernate to state it (if that fits the bill enough)
anonymous wrote :
| My plan to achieve that effect was to create my own exporter, to do that, I need to configure a Generic Hibernate metamodel exporter and create my own exporter class (inheriting I think)... but here is my problem... the docs only explain how to set the exporter class for ant:
|
|
| | <hbmtemplate
| | filepattern="{package-name}/{class-name}.ftl"
| | template="somename.ftl"
| | exporterclass="Exporter classname"
| | />
| |
|
Custom exporters are only really needed if you want very specific iteration and setup of the contexts - you can do without it in this specific case.
anonymous wrote :
| Docs do not explain how to configure the exporterclass in a eclipse *.launch file (or if is even possible)...
|
| How can I do that? (Do I need to modify the Eclipse Jboss Tools code? or this features is available but undocumented?)
|
the hbmtemplate exporter has a property exporter_class you can set - just like ant ;)
But now to how you can do it with less tweaks. I deliberatly made it so that if a template generates a trimmed empty string (e.g. a file with zero contents) then the file would not be generated.
That means you can simply put an expression in the top of the template and decide if something needs generating or not.
See http://freemarker.sourceforge.net/docs/ref_directive_if.html how to create and #if block.
anonymous wrote :
| P.D. Sorry for cross posting, but I posted this question at SeamFramework.org and nobody answered, and I am starting to think that maybe that is because this forum is a better match for this kind of question because it is more related to JBoss Tools than Seam
|
No problem - you did the right thing by posting here.
I try to monitor the Seam forum but I don't always catch the tool related questions, plus I just came back from vacation :)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4164066#4164066
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4164066
17 years, 11 months
[EJB 3.0] - Accessing EJB3 without a home interface
by nbhatia
According to the EJB 3.0 Spec:
anonymous wrote :
| The requirement for Home interfaces has been eliminated. Session beans are no longer required to have home interfaces. A client may acquire a reference to a session bean through one of the mechanisms described in Chapter 8.
|
I am trying to do exactly that, i.e. to access an EJB 3 from a remote client without a home interface. However I am getting a NameNotFoundException. Can someone help me understand how to do this?
Here's my session bean interface:
| public interface HelloWorld {
| public String getHelloMessage();
| }
|
Here's the implementation:
| @Stateless @Remote
| public class HelloWorldBean implements HelloWorld {
|
| public String getHelloMessage() {
| return "Hello World";
| }
| }
|
Here's the call from the client:
| public class HelloWorldEjb3Client {
|
| public static void main(String[] args) {
|
| try {
| // Look up the HelloWorld home interface
| Object obj = getContext().lookup("HelloWorld");
| HelloWorld helloWorld =
| (HelloWorld)javax.rmi.PortableRemoteObject.narrow(obj, HelloWorld.class );
|
| // Start using the HelloWorld object
| System.out.println(helloWorld.getHelloMessage());
| }
| catch (Exception e) {
| e.printStackTrace();
| }
| }
|
| public static final Context getContext() throws javax.naming.NamingException {
| System.out.println("Connecting to JBoss");
| Hashtable<String, String> env = new Hashtable<String, String>();
| env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
| env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
| env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
| return new InitialContext(env);
| }
| }
|
The exception is:
| javax.naming.NameNotFoundException: HelloWorld not bound
|
Here's my ejb-jar.xml. It is essentially empty. I created it just because the Maven EJB Plugin was complaining that it could not find a ejb-jar.xml. Since I am using annotations, I don't believe that I should require this file.
| <?xml version="1.0" encoding="UTF-8"?>
|
| <ejb-jar
| xmlns="http://java.sun.com/xml/ns/javaee"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
| version="3.0">
| </ejb-jar>
|
Looking at the JNDI tree, I believe that the HelloWorld bean has been deployed:
| Global JNDI Namespace
| +- helloworldejb3-app-1.0 (class: org.jnp.interfaces.NamingContext)
| | +- HelloWorldBean (class: org.jnp.interfaces.NamingContext)
| | | +- remote (proxy: $Proxy64 implements interface samples.helloworldejb3.HelloWorld,interface org.jboss.ejb3.JBossProxy)
|
So what is the right way to access this bean from a remote client?
Thanks.
Naresh
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4164064#4164064
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4164064
17 years, 11 months
[JBoss/Spring Integration] - Spring+JPA can not commit data.
by faisalaziz
Spring 2.0.6
JBoss 4.2.2 GA
JDK 6
persistence.xml
| <persistence-unit name="analytics" transaction-type="RESOURCE_LOCAL">
| <!--<jta-data-source>java:/@db.datasource.jndi@</jta-data-source>-->
| <non-jta-data-source>java:analyticsDS</non-jta-data-source>
| <properties>
| <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
| <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
| <property name="hibernate.use_second_level_cache" value="true" />
| <property name="hibernate.use_query_cache" value="true" />
| </properties>
| </persistence-unit>
|
applicationContext.xml
| <import resource="jpaDaoContext.xml" />
| <import resource="servicesContext.xml" />
|
| <!-- Datasource configuration -->
| <bean id="loanaccounting-jpa-ds" class="org.springframework.jndi.JndiObjectFactoryBean">
| <property name="jndiName" value="java:comp/env/jdbc/analytics" />
| </bean>
|
| <!-- Entity Manager + JPA Configuration -->
| <bean id="entityManagerFactory"
| class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
| <property name="dataSource" ref="loanaccounting-jpa-ds" />
| <property name="persistenceUnitName" value="analytics" />
| <property name="jpaVendorAdapter">
| <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
| <property name="database" value="MYSQL"/>
| <property name="generateDdl" value="false"/>
| <property name="showSql" value="false" />
| </bean>
| </property>
| <property name="jpaPropertyMap">
| <props>
| <prop key="hibernate.cache.use_second_level_cache">true</prop>
| <prop key="hibernate.cache.use_query_cache">true</prop>
| <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
| <prop key="hibernate.jdbc.batch_size">50</prop>
| <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>
| <prop key="hibernate.generate_statistics">true</prop>
| </props>
| </property>
| </bean>
|
jpaContext.xml
| <!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
| <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
| <property name="entityManagerFactory" ref="entityManagerFactory"/>
| </bean>
|
| <aop:config>
| <aop:pointcut id="serviceOperation"
| expression="execution(* com.primatics.analytics.service..*.*(..))"/>
| <aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/>
| </aop:config>
|
| <tx:advice id="txAdvice" transaction-manager="transactionManager">
| <tx:attributes>
| <tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
| <tx:method name="save*" read-only="false" propagation="REQUIRES_NEW"/>
| <tx:method name="update*" read-only="false" propagation="REQUIRES_NEW"/>
| <tx:method name="insert*" read-only="false" propagation="REQUIRES_NEW"/>
| <tx:method name="create*" read-only="false" propagation="REQUIRES_NEW"/>
| <tx:method name="persist*" read-only="false" propagation="REQUIRES_NEW"/>
| <tx:method name="delete*" read-only="false" propagation="REQUIRES_NEW"/>
| <tx:method name="remove*" read-only="false" propagation="REQUIRES_NEW"/>
| <tx:method name="register*" read-only="false" propagation="REQUIRES_NEW"/>
| </tx:attributes>
| </tx:advice>
|
| <!-- JPA annotations bean post processor.
| Will inject persistence related resources. -->
| <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
| <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
| <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />
|
JBoss server.log snippet
| DEBUG [org.hibernate.engine.TwoPhaseLoad] resolving associations for [com.primatics.analytics.auth.UserStatus#VALIDATION_PENDING]
| DEBUG [org.hibernate.engine.TwoPhaseLoad] adding entity to second-level cache: [com.primatics.analytics.auth.UserStatus#VALIDATION_PENDING]
| DEBUG [org.hibernate.engine.TwoPhaseLoad] done materializing entity [com.primatics.analytics.auth.UserStatus#VALIDATION_PENDING]
| DEBUG [org.hibernate.engine.StatefulPersistenceContext] initializing non-lazy collections
| DEBUG [org.hibernate.event.def.AbstractSaveEventListener] delaying identity-insert due to no transaction in progress
| DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] Completing transaction for [com.primatics.analytics.service.admin.RegistrationService.createCustomer]
| DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Triggering beforeCommit synchronization
| DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Triggering beforeCompletion synchronization
| DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Initiating transaction commit
| DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@174689]
| DEBUG [org.hibernate.transaction.JDBCTransaction] commit
| DEBUG [org.hibernate.transaction.JDBCTransaction] re-enabling autocommit
| DEBUG [org.hibernate.transaction.JDBCTransaction] committed JDBC Connection
| DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
| DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
| DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Triggering afterCommit synchronization
| DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Triggering afterCompletion synchronization
| DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] Clearing transaction synchronization
|
It seems for some reason hiberate does not like the setup. Please help me out here.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4164062#4164062
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4164062
17 years, 11 months