Edit a record from a DB table using EJB3? - ejb-3.0

im quite new to EJB3 and was wondering if it is possible to edit a specific record from a table using EJB3?
If so, are there any tutorials and examples on how to do this?
Thanks in advance

Since entity beans were deprecated in the EJB3 standatd, you'd do this using either plain JDBC or JPA, but neither of these requires EJBs to be used.

Related

what is the best way to create session from java spring boot using oracle Database?

I created user in oracle database and I am trying to create session but I find many ways in spring boot so what is the easy way if I want to create classe connections using the Username and Password ?
You can jdbc template, spring data JDBC or spring data JPA, well depending on your use case.
If your data model is quite complex, you should avoid using the JDBC template as you will need to write prepared statements which can be cumbersome. JPA will allow you to use object-oriented programming principles and also will help you map the entities to your database columns.
For example, if you are going to use spring data JPA, you need to set the application properties as follows:
spring.datasource.type=oracle.oracleucp.jdbc.UCPDataSource
spring.datasource.oracleucp.connection-factory-class-name=oracle.jdbc.pool.OracleDataSource
spring.datasource.oracleucp.sql-for-validate-connection=select * from dual
spring.datasource.oracleucp.connection-pool-name=UcpPoolBooks
spring.datasource.oracleucp.initial-pool-size=5
spring.datasource.oracleucp.min-pool-size=5
spring.datasource.oracleucp.max-pool-size=10
This would behind the scene create an Oracle Datasource. In this example, we are using Oracle Universal Connection Pooling. You can also use HikariCP which is quite popular.
check this out
If you want to use UCP with above properties then you must have SpringBoot version higher than 2.4.0.
Check out the Spring Boot code sample on GitHub.

Creating tables on fly with Spring Boot Data JPA

Trying to build application where tables & its fields are managed by master table & creation of tables & its fields happens on demand, on fly based on user data posted to server.
Tried to look over similar question like this but wasnt able to find clue how to execute dynamic queries in DB without creating Repository & Entity in spring boot.
Robert Niestroj is correct when he writes in the comments
If you have dynamic tables JPA is the wrong approach. JPA is for static schema
I guess in theory you could do something where you generate code and possibly restart your ApplicationContext but it is bound to be really painful and you won't benefit from using JPA.
You should look into more dynamic technologies. MyBatis and plain old JdbcTemplate or NamedParameterJdbcTemplate come to my mind.
Possibly with your own abstraction layer on top of it if you have recurring scenarios.

hibernate ejb3+Tomcat+Openejb or Spring+hibernate for an exsiting GWT2 project

I used GWT2+DAO pattern for my apps and it's work correctly. Now my BD as grown a lot and i want to manage it more easier. So I want to use an ORM.What i want to do is to keep my first DAO implementation and use hibernate for my new classes. But I read a lot on internet and I'm very confused about the way to deal with this.
which solution between hibernate ejb3+Tomcat+Openejb and Spring+hibernate could be better for me?
also which one could be the fastest?
Should I change all my dao to use hibernate methods or should I use the both?
NB: I'm just started to read spring doc, but I have already read hibernate doc.
thanks.
I think the change you need only affects the back-end, hence has nothing to do with the server or container you are using.
Rather in your DAO, when saving new pojos, use hibernateTemplate instead of what you were using.
It would be advisable to actually be consistent, if you are going to use hibernate, use hibernate for all your db manipulation.
Optimization is a whole chapter on itself, I think you should focus on getting your db changes for now, then worry about the speed when everything works.

How can I read the db table instead of reading the property in Spring?

I want to read properties from database tables instead of reading property files in Spring.
How can I achieve this? At the first time, I thought that I have to override the spring-context related classes. But I think there is easy way to implement this or Spring already provides this feature.
Fortunately, I found the solution like the below link.
http://www.albinsblog.com/2014/07/loading-configuration-properties-from.html#.VNBK9Gjkep8

Hibernate with MongoDB

I'm looking for resources showing how to integrate MongoDB with Hibernate (preferably from within spring) so that I can switch between a RDBMS and a NoSql alternative: does anyone have experience doing this?
You can't easily do this. The point of Hibernate is to map Java Objects to a relational database. Although Hibernate abstracts a lot of details away you still need to understand how relational databases work with things such as foreign and primary keys, and the performance implications of queries you run. MongoDB requires an entire different way of designing your database focusing on objects instead of columns and tables. while you may be able to create a Hibernate dialect for MongoDB creating a design that would work on both a relational database and a NoSql database will give you a design that works poorly on both.
What about Hibernate OGM? It provides JPA for No-SQL databases.
Migration would be easier if you use Spring MongoTemplate (similar to HibernateTemplate). Among its features is support for JPA annotations (although, I'm not sure to what extent).
See more: http://www.springsource.org/spring-data/mongodb
You'll need the following:
Add spring-data-mongodb JAR to your project (available in maven
central).
Add mongo-java-driver JAR to your project (available in
maven central).
Use the provided MongoTemplate class in a similar
manner to HibernateTemplate. E.g.:
mongoTemplate.findById(id, MyClass.class);
mongoTemplate.insert(myObject);
Here's a concrete example with code: use-spring-and-hibernate-with-mongodb
If you are using Java then you can use Hibernate OGM it provides Java Persistence support for NoSQL databases.
For more details visit http://hibernate.org/ogm/
There is nice work done earlier as:
http://pragmaticintegrator.wordpress.com/2011/07/14/use-spring-and-hibernate-with-mongodb/
http://pragmaticintegrator.wordpress.com/2011/07/27/unit-test-your-springhibernate-and-mongodb-setup/#comments
refer to these links. it will be helpful to you.
There is also kundera, which uses JPA-annotations to read/write your object from/to a mongodb. If you ara familiar with hibernate, it should be quite straightformard to use.
I recently tried Morphia, which takes the same approach, but with its own annotations.
It works fine
May this blog helps: http://drorbr.blogspot.com/2010/02/migrating-springhibernate-application.html
Here Dror Bereznitsky describes nicely how to integrate a sping/hibernate based solution with mongodb.
For the sake of completeness, PlayORM also supports MongoDB now. PlayORM is an object NoSQL mapping solution so you can write POJO’s and let it deal with all the details of marshalling/unmarshalling to MongoDB. Visit its documentation here
I think Hibernate provides desired functionality. Take a look at this, found on their official website:
Mixing several NoSQL datastores in one application, e.g. use Neo4j for your friendship graph and MongoDB for your blog posts. Or mix NoSQL and relational databases.
reference
Well just to give you an example, I am doing somehting simmilar. In ColdFusion, Hibernate is integrated and in order to save your Hibernate Object, you hvae to do EntitySave(Obj). However what we have done is build the Orm object, and then use a mongoDB Coldfusion component and just save the object by going mongo.Save(obj,collectionName).

Resources