Circle Hibernate Dependency in in multy modul project - spring

I have 2 maven modules:
auth module (user entity)
news module (article entity)
So, I have problem, with circle dependency between modules, because I want to have biderectional dependency in Hibernate with user and atrticle. Because of this i need to add module dependencies
MAVEN (auth -> news -> auth ...)
I have some ideas, but I not sure of them:
Do not use biderectional in Hibernate
Store entities together but I dnot sure that is good idea, beacuse this moduels is independent
Create own user for news, and synchronize it with auth module
Can you give some advice how resolve this problem

Related

ClassCastException in multi-module project running on Quarkus (gradle)

I seem the get weird classcast exceptions in multi-module project.
Here is an shortened overview of the project structure:
Project: dto-commons
contains
-> AuditingEntityObjectSelector (a normal java class)
-> AbstractAuditingEntity (JPA #MappedSuperClass)
Project: model
contains lots of JPA entities, which all extend AbstractAuditingEntity from the project 'dto-commons'
depends on
-> dto-commons
Project: selectors
contains
-> SampleRequestSelector (a normal java class which extends AuditingEntityObjectSelector from the project 'dto-commons'
depends on
-> model
Project:mainservices
- model
- selectors
- dto-commons
Project:rest-api --> This project is launched with quarkusDev (gradle)
- mainservices
I've created a little testresource where I inject some services, an EntityManager etc.
Everything seems to be working, except that I get very weird ClassCastExceptions
java.lang.ClassCastException: class
com.geodesk.queryinfrastructure.selector.SampleRequestSelector cannot
be cast to class
com.geodesk.domain.queryinfrastructure.AuditingEntityObjectSelector
Some debugging shows me the following:
new SampleRequest() instanceof AbstractAuditingEntity --> true (which is correct)
new SampleRequestSelector() instanceof AuditingEntityObjectSelector --> false (which is NOT correct)
This is probably a classloading issue, but I can't figure out what is causing this.
SampleRequest.class.classLoader == AbstractAuditingEntity.class.classloader --> true
SampleRequestSelector.class.classLoader == AuditingEntityObjectSelector.class.classloader --> false (don't know for sure, but I think that should be true)
Anyone can point me in the right direction?
(note that all projects do have an empty META-INF/beans.xml in their resources dir)
This looks like another installment of our class loader issues. We are currently actively working on fixing them but it's not an easy subject.
I suppose you only have the issue with quarkusDev? Not when you execute the -runner.jar?
It would be helpful if you could try to put together a simple reproducer and open a GH issue so that we can be sure the current class loader work fixes this issue too.

Generating CRUD with Appfuse Maven Plugin(AMP)

A few Days Ago I Used the Command mvn appfuse:gen to generate CRUD with the Appfuse. But it Generated the folllowing files/classes for a given class (say, Category):
1) Category-validation.xml
2) CategoryAction-validation.xml
3) CategoryAction.java
4) CategoryActionTest.java
5) CategoryForm.jsp
6) CategoryList.jsp
I Expected it will generate the CategoryDao/CategoryDaoHibernate or maybe CategoryManager/CategoryManagerImpl Classes at least !!! But I was wrong.
Instead, we have the following code in CategoryAction class:
private GenericManager categoryManager;
And this is in Contradiction with the appfuse's standard tutorial (See this Page)
Can anybody tells me how to generate the CategoryDao/CategoryDaoHibernate and CategoryManager/CategoryManagerImpl Classes for the project?
Use -Damp.genericCore=false when you run appfuse:gen. Like the following:
mvn appfuse:gen -Dentity=Category -Damp.genericCore=false
It's already explained in following post:
Stackoverflow: running “mvn appfuse:gen” does nothing
but basically, it's the same like previous post from Matt Raible
After running that command (for EVERY entity), you'll get:
DAO layer
DAO interfaces
DAO (Hibernate) implementation
Service layer
Manager interfaces
Manager implementations
Webapp layer
Controllers (if you are using SpringMVC framework)
JSP pages
and whole bunch of all other required resources (various Resource Bundle properties, Spring XML files, Menu configurations...). Of course, it's all based on your model, your defined JavaBean classes.
After that, you just need to put some extra code inside implementation classes if you need some customized functionalities, some additional business logic.
I hope it helps.

Spring configuration - Multi module Maven project

I have a big web application. As part of optimizing the code, I've split them in to three modules.
Module 1 : Web
Module 2 : driver module
Module 3 : Reporting module
Here Module 1 & Module 3 are spring projects, where as the module 2 is currently pure Java module.
I want to access the Module 3(which is in spring) through Module 2.
App context xmls are present for module 1 and module 3. (say m1.xml and m3.xml)
I've included m3.xml in m1.xml as
<import resource="classpath*:m3.xml" />
In Module 2, I'm trying to introduce autowiring reference to classes in Module 3. But the first usage of the autowired field throws a Null Pointer exception.
In component scan, I've added the base package, so that it will be able to identify the class.
Can any one guide me how to rewrite Module 2 to fix this issue (ApplicationContext xml ? etc)
I'm using spring 3.1
I figured out the issue !
Actually from Module-1(webapp), I'm calling the driver module and from there calling the reporting modules.
The issue was that from driver to report, I'm calling using new references (new Report() ), so these are no longer managed by spring container. Normally objects managed by spring container can only be wired automatically. By default, the Autowired references in new() created classes will not be autowired.
The issue can fix in two ways
http://seniorjava.wordpress.com/2013/04/03/spring-configurable-magic/ (Spring - #Configurable)
OR
http://sujitpal.blogspot.in/2007/03/accessing-spring-beans-from-legacy-code.html (share the app context through static methods. This has side effects on unit testing.)

Do I need a DependencyResolver in my MVC/MEF app?

I've seen articles online about how to implement them, but I still don't understand exactly what they do, and if I need one in my application. My application will have a HostApp that has many plugins with controllers and views in them. Will I need a custom DepedencyResolver in my app?
If you have any questions please let me know! Thanks!
No, you don't 'need' one. If you want to use dependency injection, MVC allows you to hook up a resolver so you can inject dependencies at various points, most typically is injecting some dependency into your controller.
public class CustomerController
{
public CustomerController(ICustomerRepository repository)
{
}
}
It's up to you to use it or not if your application calls for it. This depends on how you have your layers and dependencies setup, but you dont 'need' it, but it can help in many cases.
Check out Dependency Injection in .Net by Mark Seeman for the best ref on the subject. Many questions could be asked about your implementation since you may have plugins and optional dependencies which is a bit out of the scope of the question but feel free to post more : )
http://manning.com/seemann/

Domain classes in grails

How to make relationship between two domain classes in grails . I already have one domain class from the plugin (spring security plugin) and i want to link USER domain class from plugin to the Profile domain class . What is the best way to do it?
See the GORM documentation for a good overview. For a one-to-one relationship as I assume a profile would be, you could simply do the following:
class User {
Profile profile
}
class Profile {
// only needed if you need to refer to user from the Profile instance
static belongsTo = [user:User]
}

Resources