JPA select values from dynamicallay created table - jpa

I have some dynamically created tables(using native queries). So I do not have the names in my entity but stored in a db table. Now I want to retrieve datas from each. I want to use only JPA.

To use JPA you must have Entity that maps on to any table that you want to access. If you don't have that then JPA is not for you, and just use JDBC. Can't get simpler.

Related

JPA: Map a group of table columns extracted by native query to entity

I know that it is possible using #SqlResultSetMapping but I want to select not whole entity from the database but some fields and then map i to my entity using one of the constructor which accept that fields. Is that possible to map result with #EntityResult for only a few #FieldResult? I was trying to do that and all the time I get error which said that there is not specify mapping for some fields which exist in that entity.
The disadvantage of #SqlResultSetMapping is that you have to select all the columns.
The alternate way of doing this manually iterate over the DB result and populate your objects.
Well, if you are using JPA 1.0 your only option (not considering the manual mapping, of course), is to use #SqlResultSetMapping and map the whole table columns. With JPA 2.1 you can add a javax.persistence.ConstructorResult (see docs here) to map only the needed columns.

Why JPA generate Entities from Tables orders fields alphabetically?

When generating JPA Entities in Eclipse using JPA Tools, the fields are ordered alphabetically instead of the order defined in the Tables.
My DB
JPA Generated Entity
Any idea how to switch this off?
The problem is if I set ddl-auto, then the columns in the DB Table are generated in the Entity order which makes it very confusing when browsing the data using the DB.

How to use Entity framework to pass Table Valued parameter to Stored procedure

I have tables with 2 level hierarchy, Parent->Child->GrandChild
I have create stored procedure with three table valued input parameter ParentTable, ChildTable, GrandChild Table.
Now, I want to consume it in .net using entity framework.
Solution all over internet is, create DataTable in .net , store data in it and pass the same as parameter in stored procedure.
But, I want to use entities instead of data table as data is stored in entity objects. Please suggest. Many Thanks.
You need to have look at this question
Create data table from entities and then pass it to the stored procedure. I haven't tried the code, just showing you the path to go. I hope it may help, looking for better solution.

spring dat jpa batch update using repository

I'm using spring data jpa repository to handle my sql-server database, Now my problem is how to batch update to my table, because My table-java bean not contains all the columns from the table, so if I do repository.save(List<>), it may overwrite all the other columns to default value if they are not mapped in my java bean, so now, i just write like below to write native sql to update each column:
So how to batch update some fields?
In order to update a JPA entity object, you would have had to fetch it first. Once all the objects are fetched then you can update just the properties you want and save the List<Zip> in batch. This will only change the database columns that you specifically change.

Adding a property to an Entity Framework Entity from another table

I'm just starting out with the Entity Framework and ADO.NET Data Services and I've run into an issue that I can't seem to figure out. I have two tables, one that has user information and the other that has a created by field. Within the database, there isn't a foreign key between these tables. The user table contains an arbitrary Id, a username, and a display name. The created by field contains the user's username. In my entity I would like to have the user's display name since this is what I need to display and expose over the ADO.NET Data Service? I'm aware that I could restructure the database, but I was hoping that I could do the join using the username as I would in a SQL statement.
Thanks in advance,
-Damien
You can make a view using a join of both tables, and then use this object to display the user's name.
There's some info on mapping custom queries here.