[Beginners Corner] - Re: Jrules engine
by jetimms
I have a similar problem to the original poster.
Unfortunately, I'm new to Eclipse, Java, and JBoss. That being said, I understand and humbly accept the massive learning curve I personally must navigate to better understand these tools. I have read section 2 of the documentation and have a basic understanding of the expert systems from My installation didn't work the same way, which leads me to this post.
I have been successful in creating a new JBossRules project which seems to always have the sample Hello World in it somehow.
I got that to run, which was a small mildstone for myself.
Now I'm loading the Drools example from the JBoss download page, but the example drools files can't seem to find their related example java files.
When I build, I get 4,692 Problems (or opportunies. Glass half full, right?)
Each one has a funny looking red X on it. Inside the Drools example project, the HelloWorld.drl had a x on the rule name and the conditional. As a matter of fact, that's true throughout the example project.
I have three questions:
1) Where can I find a short explanation (3 sentence or less) of what I'm seeing?
2) What is the importance in maven as to if and why I might need it (or how to tell that I have it?)
3) Do I need subversion for Drools examples to work?
Thanks.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4061385#4061385
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4061385
18Â years, 9Â months
[JBoss Seam] - Transaction management in EntityHome subclass
by mbertelsen
I have an entity with a two-field unique constraint. Due to not being able to write a validator that validates two fields of an entity at once (or am I wrong here?), I ended up subclassing the EntityHome in order to run my object-level validation before the superclass update() and persist() get called. However, because the instance entity is managed, and EntityHome uses the seam-managed persistence context and transaction management, by the time my code for validation runs, the managed entity has already been updated by JSF. So when I try to run a select query to determine if the two fields together are unique, hibernate is automatically flushing the write to the entity, which throws the EntityExistsException i'm trying to avoid.
I ended up with the following solution, and would like to know if there's a better way:
| @Name("databaseServerHome")
| public class DatabaseServerHome extends EntityHome<DatabaseServer> {
| @In
| EntityManager entityManager;
|
| @In FacesMessages facesMessages;
|
| @Override
| public EntityManager getEntityManager() {
| return entityManager;
| }
|
| @Override
| @Factory("databaseServer")
| public DatabaseServer getInstance() {
| return super.getInstance();
| }
|
| // ... (removed for clarity)
|
| @Override
| @Rollback(ifOutcome="invalid")
| public String update() {
| // set flush mode to COMMIT so that validateUnique can run a query to
| // check uniqueness without triggering a flush
| // This is required because we have a managed entity with dirty changes
| // (already applied by JSF) and now need to validate them after the
| // changes have been made
| getEntityManager().setFlushMode(FlushModeType.COMMIT);
| if (validateUnique()) {
| return super.update();
| } else {
| return "invalid";
| }
| }
|
| protected boolean validateUnique() {
| DatabaseServer ds = getInstance();
| String existenceQuery = "select ds from DatabaseServer ds where ds.serverName = :serverName and ds.port = :port";
| try {
| DatabaseServer ds1 = (DatabaseServer) entityManager.createQuery(existenceQuery)
| .setParameter("serverName", ds.getServerName()).setParameter("port", ds.getPort()).getSingleResult();
| if (ds1 != null && !(ds1.getId().equals(ds.getId()))) {
| facesMessages.add(FacesMessage.SEVERITY_ERROR,"You cannot have two database servers with the same Name and Port");
| return false;
| } else {
| return true;
| }
| } catch (NoResultException nre) {
| return true;
| }
| }
|
| }
|
One last minor annoyance is that Seam is adding a FacesMessage that reads "Transaction Failed" when it rolls back - how do I alter this behavior?
Thanks!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4061382#4061382
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4061382
18Â years, 9Â months