I'm faced with a new challenge of supporting multi-tenancy with JPA. I've searched around and it looks like JPA doesn't really offer anything that is usable in the long run. I see a lot of people talking about spring security and picking the tenant datasource from it's context. I don't want to use hibernate or eclipseLink too. Not sure what is the best solution for my problem.
I have an independent service running that needs to kick off queries to various database at random times. I am currently using AWS Redshift as my data store. I will have a connection string available to me as requests come in. I am really un-easy as to what platforms to use to accomplish this? My service is also using spring boot. Anyone have any thoughts? Thank you!!
Related
Is there a way to implement schema multi tenancy in dropwizard?
The only solution I've found so far is https://github.com/flipkart-incubator/dropwizard-multitenancy but that is using descriminator multi tenancy.
We basically had the same problem. We wanted to support multi-tenancy, but not only on database level. Different customers have certain services configured differently. In order to avoid passing through the tenancyId everywhere, we came up with a custom scope using Guice. This way, every service that is #TenancyScoped can get its own predefined configuration or simply the tenancyId in its constructor. Then your DAOs can use different schemas based on the tenancyId.
It works quite well for us, even though it might not properly scale if you have too many (maybe > 1000, really depends how complex your configuration is) tenants.
I have posted the details about Guice and custom scopes here: Multi tenancy with Guice Custom Scopes and Jersey.
I had the same problem and I created a multitenant hibernate bundle by modifying the current hibernate bundle code. If you still have the requirement you can check it out.
Here is the link: https://github.com/uditnarayan/dropwizard-hibernate-multitenant/
New to Java EE6 and I'm trying to set up a JDBCRealm. Many of the examples suggest making the tables that hold user/group information by hand in SQL.
Is there a more standard "JPA" way of doing it though? The tables Glassfish expects don't fit with the kind of table structures you'll end up with if you use e.g. a OneToMany mapping (which is what I was hoping I could use).
I read Glassfish still uses JDBC to accomplish the JDBCRealm, which would explain why. And I came across this blog which suggests a way to do it with JPA.
http://www.codeproject.com/Articles/238779/J2EE-JDBC-based-authentication-with-JPA-Entities-i
But is there an 'official' way to do it with JPA? I want to make sure I follow best-practice to ensure I have a secure application.
Thanks
A few months ago i wanted to create my JDBC Realm with glassfish and i also had lots of doubts. I will try to explain you more or less how i did it using JPA.
Many of the examples suggest making the tables that hold user/group
information by hand in SQL
I disagree, if you are using JPA for other tasks related to persistence why would you make an exception when regarding to security. So JPA is a good idea. Copy/Pasting a chunk of SQL in your DB console is easy but better if you have entities that will automatically will always create those tables for you when you deploy your app.
The tutorial you are following is fine, i think there is no such think as a best practice.
I will give you some resources that i think will help you creating the JDBC realm.
Maybe you are interested in something a bit more simple, just to warm up, in that case have a look at this post:
http://javing.blogspot.in/2012/05/here-in-this-video-you-can-see-how-i.html
It talks about ROLE based security in glassfish, i think it can give you some tips.
If you want to know how to create the JDBC realm with JPA, follow this question i made time ago, at the end you will find the solution:
Glassfish 3 security - Form based authentication using a JDBC Realm
If you paste some code we could help you trouble shouting in case you get stuck.
I went to an interview into a IT consultancy company last friday.
The Interviewer asked me about my project and what was my participation in it.
Suddenly he threw one question on hibernate. His question was as follows
"If i have an project which has been developed in an MVC architecture using Java EE environment, but using JDBC for Database interaction, how will i integrate Hibernate into it. I don't want to disturb the existing code, all the previous JDBC code should be intact. "
I told him that we an add all the features of hibernate in the existing code, as it only requires Config files, Entities thats it. The old code of JDBC may itself be using Datasourse for getting connection, the same datasourse can be looked up using JNDI to build a session factory in Hibernate, not a big deal.
But the interviewer was not happy with my answer, he needed some more explanation.
I was not able to impress him.
So can you please suggest what should be the probable answer for the above question.
Or at least give me one hint so that i can come to an answer.
I think he wanted answer like the following.
Typical application design requires layers separation. There are the following classic layers: web tier, business logic and DB. There is a thin layer named DAO (Data Access Objects) that is written in java and plays a role of "middleman" between business logic and DB. It sounds that this tier is implemented using plain JDBC.
So, there is not a problem to replace this and only this layer with Hibernate based one.
Now you can add more details about how you are configuring Hibernate and integrate it with the rest of your application.
Not an exact answer and you did not mention which framework your application use but if your application uses Spring framework, this my question and its answer's will be helpful to you but my question is reverse as I wanted to integrate jdbc with hibernate.
I think he was probably looking for you to explain how you might:
put Hibernate wrappers around existing SQL queries, or
create Hibernate bindings for legacy SQL tables, or
integrate Hibernate and classic JDBC using container-level transactions.
(It is clear that he was not asking about how you would replace the old JDBC code with Hibernate code ...)
But of course, you'd really need to ask him what knowledge / experience he was expecting you to demonstrate in answering the question.
I'm wanting using JPA in ear project. Development project must be started ASAP so I have not a lot of time to research and investigate. Could you say please JPA API is restricted functionality of Hibernate or no. At this moment I'm using Hibernate directly. For example in future I'm planing to use hibernate-search and maybe hibernare-validate and -shard. Can I be sure that in future I will not have problem with using this.
And one more example - can I use HAR archive and JPA together.
Why JPA? For project will available RESTful service (jersey or resteassy implementation). And as I looked in much case using JPA for this. I'm a newbie in this so it's only my IMHO. May be i mistakes.
Thanks a lot.
Best regards
Artem
JPA is a subset of hibernate, but you're not limited to it. If you need a hibernate specific feature, you can generally use it at the cost of being tied to hibernate. For example, we've mixed in hibernate annotations with JPA ones, including the validater ones, without trouble.
JPA in theory lets you change the persistance provider later.
Sticking to only JPA compatible configuration can cause more trouble that is solved by the dubious promise of seamlessly swapping providers however.
I facing problem of database connection in my project in which i used struts. I cant understand that how i manage my database connections. I want my site good in based on accessing becoz it will get million after launch.
And also face heap size problem in that .
I cant understand that how i will manage my architechture.
Plz guide me,if some one have the knowledge .
I want good java architecture with good management of database connection.
I would suggest you to use Hibernate for DB operation.
It is very good ORM tool
There should be 3 modules atleast for your case of architecture.
1)WebApp
2)Service module
3)Database [Hibernate Module]
Spring has some very good facilities to help you manage DB connections. Have a look at part IV of the documentation : http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/spring-data-tier.html
Spring can help you wether you want to do plain JDBC / SQL or if you want to use a more fancy ORM like Hibernate.
If you want to sustain really high load, that's of course just the begining. You will need a lot of profiling, measuring, tweaking ...
You can look into the layered architecture approach. Struts itself is based upon the MVC architectural pattern.
From Wiki, ...In MVC:
Models are not data access objects; however, in very simple apps that have little domain logic there is no real distinction to be made.
Many applications use a persistent storage mechanism such as a database to store data. MVC does not specifically mention the data access layer because it is understood to be underneath or encapsulated by the model.
So, you can comeup with you own data access layer that would work underneath your Model; Checkout A Simple Data Access Layer using Hibernate