Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!

Tony Evans

Ranch Hand
+ Follow
since Jun 29, 2002
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
6
Received in last 30 days
1
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tony Evans

One to one and one to many relationships, if a parent has been deleted, you can set  orphanRemoval true. Will delete the orphan child.

But it seems there is to no way within JPA to remove the orphan for a many to many parent.
I feel the best way is to periodically run amother programme on the DB itself dedicated to removing orphans

Is this the best possible soultion.
That is roughly what I have done. I follow MVC. I have a control layer, a service layer and a repository layer, extending JPARepository. I dont get this problem using Hibernate session factory directly. I guess its one of those things, i will have to play around with, to get working.

Thanks for the reply. Its always good to discuss design, which si just as importannt as coding/
You have set up your session factory in your context.xml

why dont you pass that into your repository and then create your hibernate  sessions  that way.


Then in your repository
[code]
public class FundRepositoryImpl extends MappEntitiesAbstract implements FundRepository {

private SessionFactory sessionFactory;

private static final Logger logger = LoggerFactory.getLogger(FundRepositoryImpl.class);

public void setSessionFactory(SessionFactory sessionFactory) {
       this.sessionFactory = sessionFactory;
   }
   
@Override
public List<FundPOJO> findFunds(List<Long> fundIds) {
Session session = this.sessionFactory.getCurrentSession();
Cache cache = sessionFactory.getCache();
Transaction tx = session.beginTransaction();
Query res = session.createQuery("FROM Fund f WHERE f.fundId IN :fundIds").setParameterList("fundIds", fundIds);
List <Fund>fundsList = res.setCacheable(true).list();
List<FundPOJO> funds = mapFunds(fundsList);
tx.commit();
return funds;
}
[code]
Yes it is a detached problem. Lets say I create a object called Bank with a many to many mapping to an acount, and account has a many to many mapping to a fund.

Then I want to update the bank object by adding  another account but maps to the same fund, that will cause the error.  
What I can do is map the account to the bank, and then in a seperate call to the repository, map the fund to the account, and that way it works.

Yes , have a seperate entity for each object you are saving. I would have PersonPOJO map to a PersonEntity, and save that enity in a personRepository which would have my hibernate or JPA functionality.
Also think of caching, if you are going to cashe in hibernate second level. It would be as an entity.
I am getting the following error


I know what is causing the problem, but not how to fix it.

i have the following manyToMany mapping

Bank <-> Account <-> Fund

I have a Bank BankId 123 that bank has Account accountId 1234 with fund fundId 12345
If I add to Bank  BankId 123  a new Account accountId 1235 but with with fund fundId 12345
It will fall over

It wont allow me to add an existing fund, from one account to another account, if both accouts are mapped to the same Bank.  I am using org.springframework.data.jpa.repository.JpaRepository; save() for my entity

The Entities are






Thanks for any help in a work around.
I trying to download eclipse. https://www.eclipse.org/downloads/packages. I Have tried 4 times, each time the installer just hangs, what happen to just a nice simple download zip and unzip. Now even the package is taking almost an hour.

anyone else with the same problems. almost tempted to try intellij, although they have horrific downloads, which was why i kept with eclipse.
3 weeks ago
I am running Ehcache as a Hibernate second session Does this logging of my second search say its working


Does this say its just adding it and hit just means its added
3 weeks ago
Hi ok what I needed to do was the following for my config class I added a link to pick up my Spring.xml @ImportResource("classpath:/spring.xml")

I think the reverse is happening, because I have set my


Its overwriting the FundRepositoryImpl in my XML.

Is there a way to say dontoverwrite the FundRepositoryImpl in my XML.
SessionFactory is not being loaded. I think I know what the problem is , i just need someone else to confirm it.

I am using a mixture of autowire and xml, so my service bean is autowired, and calls FundRepository which is identified with the @Repository. But at the same time FundRepository is an XML defined Bean.
My question is, is it possible to mix autowired and XML defined beans ?.

Looking at my config I cant see anything wrong, but I have a hunch, that its not picking up the  FundRepository from the XML, because of the @Repository.


The spring context is


Called from a service nean
Hi yes I have tried with consume, but I should not have to, its should look at the header. I am sure I am missing a dependency in my pom.xml, but have no idea what.

[code]
@RequestMapping(value = "/findfunds/", method = RequestMethod.POST, consumes = "application/xml")
public Funds findBanks(@RequestBody FundRequest request, UriComponentsBuilder ucBuilder)
throws ParseException {
logger.info("Find Funds");
Funds funds = fundService.listFunds(request.getFundIds());
return funds;
}
[code]
3 weeks ago
Sorry I should add the header is set to application/xml.in fact I tried both application/xml \nd text/xml
3 weeks ago
I have seen that this is quite a common problem, but it seems to trigger  a whole raft of possible soultions. I have a simple POJO




In my pom I have


And a controller



in all the examples I am told I only need


the header is text/xml

request is
3 weeks ago
Hi I have a Entity, I have configured as a cache Fund


I didnt want to create a cache fund, as I have nore entities to add so set up the default in my ehCache.xml



This outputted the debug message


I have no idea what this message means, but I assumed that skipping for fund, means its not being added to the CacheManager, sp i created an concrete object that extends CacheDecoratorFactory


cache returns


But properties is set to null.

So I took a guess and added Fund to the properties


And got the following error


So now I have got to the point where I am confused. I have a feeling, I dont need a CacheDecoratorFactory,  to set up the fund cache, so I am not sure what the original debug  message skipping for fund means.

Thanks for any help. Tony
4 weeks ago