Persisting view created entities

I have a query something like this where I am trying to select from a view and then persist the view result as new entities of a certain class.

e.g. create new objects of MyEntity.class somewhat like follows.

I have named the view’s columns identical to the entity’s columns in the database:

try (Transaction tx = persistence.createTransaction()) {
            EntityManager em = persistence.getEntityManager();
            List<MyEntity> myEntityList = em.createNativeQuery("select * from some_view", MyEntity.class)                    

 myEntityList.forEach(myEntity-> {


But I keep getting duplicate key violation even though the MyEntity objects do not actually exist in the MyEntity table in the database.

Wondering a better method of doing something like this if possible without actually having to convert the nativeQueries Object[] list to new MyEntity objects. I am trying to process thousands of entities and want it as quick as possible.

Note: the MyEntity class is a BaseGenericIdEntity<MyEntityId> type class

Is this possible?

Have managed to resolve by just copying the view results from the view directly to the MyEntity table as a native query.

To curious to know whether or not the above can be done however.