Getting Unable to persist data entity, Error while commiting the transaction - tridion

I successfully managed to write deployer extension as well as storage extension.
And below are the logs which I took from core logs, which shows everything is loaded perfectly!!
2013-01-08 11:30:19,759 INFO BundleConfigurationLoader - Added 'PublishAction' for storage 'persistence' with 'com.tridion.storage.dao.JPAPublishActionDAO'.
2013-01-08 11:30:38,259 DEBUG JPAPublishActionDAO - Constructor of JPAPublishActionDAO- storageId:searchdb
2013-01-08 11:30:38,259 DEBUG JPAPublishActionDAO - Constructor of JPAPublishActionDAO- entityManagerFactory:true
2013-01-08 11:30:38,259 DEBUG JPAPublishActionDAO - Constructor of JPAPublishActionDAO- storageName:PublishAction
2013-01-08 11:19:38,400 INFO Module - No TransformProcessor configured, will not transform files before deployment for module com.tridion.custom.extensions.SearchPageDeployer
2013-01-08 11:30:38,400 DEBUG SearchPageDeployer - Constructor of SearchPageDeployer //This is my PageDeployer Constructor
2013-01-08 11:30:38,744 DEBUG SearchPageDeployer - Called processPage from SearchPageDeployer //This is my process Page of pagedeployer class
2013-01-08 11:30:38,572 DEBUG SearchPageDeployer - SearchPageDeployer Called processItem
2013-01-08 11:30:38,572 DEBUG StorageManagerFactory - Default storage provider has caching set to: false
2013-01-08 11:30:38,572 DEBUG StorageManagerFactory - Loaded following dao Properties[publication=0, typeMapping=PublishAction, storageId=searchdb, cached=false] for publication/typeMapping/itemExtension: 0 / PublishAction / null
2013-01-08 11:30:38,572 DEBUG StorageManagerFactory - Loading a non cached DAO for publicationId/typeMapping/itemExtension: 0 / PublishAction / null
2013-01-08 11:30:38,572 DEBUG StorageManagerFactory - Wrapping DAO's, currently 0 wrappers installed
2013-01-08 11:30:38,572 INFO JPAPublishActionDAO - Entering Method: JPAPublishActionDAO.PublishAction.store
2013-01-08 11:40:33,228 ERROR SearchPageDeployer - SearchPageDeployer - Exception occurred com.tridion.broker.StorageException: Unable to persist data entity, Error while commiting the transaction, Error while commiting the transaction
Now when I am trying to store the data in my table I am getting "Exception occurred com.tridion.broker.StorageException: Unable to persist data entity, Error while commiting the transaction, Error while commiting the transaction"
is this any issue with my Entity class or something I am missing.
EDIT: After the enable logger level "ON" in logback xml.
I got below exception in core files:
2013-01-08 14:42:10,713 DEBUG SQL - insert into AUTN_ITEMS (ACTION, FLAG, ITEM_TYPE, LAST_PUBLISHED_DATE, PUBLICATION_ID, SCHEMA_ID, TCMURI, URL, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
2013-01-08 14:42:10,728 DEBUG AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2013-01-08 14:42:10,744 DEBUG JDBCExceptionReporter - could not insert: [com.tridion.storage.dao.PublishAction] [insert into AUTN_ITEMS (ACTION, FLAG, ITEM_TYPE, LAST_PUBLISHED_DATE, PUBLICATION_ID, SCHEMA_ID, TCMURI, URL, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?)]
com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert explicit value for identity column in table 'AUTN_ITEMS' when IDENTITY_INSERT is set to OFF.
Thanks

The error you're getting is suggesting that your ID column is not defined correctly as an identity or that you're trying to manually set a value to the autogenerated value in this column.
Hope this helps.
Regards,
Daniel.

The ID column should be set to auto increment at db level. Have a look at my original article on sdltridionworld for an example http://www.sdltridionworld.com/articles/sdltridion2011/tutorials/extending-content-delivery-storage-sdltridion-2011-1.aspx
"For SQL Server, column ID is defined as IDENTITY(1,1), so it increments automatically by one, without us having to specify value.
For Oracle, column ID needs to be defined using a Sequence (that generates the values), like this:
CREATE SEQUENCE SEQ_PUBLISH_ACTIONS MAXVALUE 999999999999999 CYCLE START WITH 1
/
CREATE OR REPLACE TRIGGER PUBLISH_ACTIONS_KEY
BEFORE INSERT ON PUBLISH_ACTIONS
FOR EACH ROW
BEGIN
  IF :new.ID IS NULL THEN
    SELECT SEQ_PUBLISH_ACTIONS.NEXTVAL INTO :new.ID FROM DUAL;
  END IF;
END;
/
"

Above issue was in my Entity Class, I need to add below annotations for my identity column.
#Id
#Column(name = "ID", unique=true,updatable=false,insertable=false)
#GeneratedValue(strategy = GenerationType.AUTO)
private long id;
Please do suggest if any changes are required.
Thanks

Related

Flyway "ORA-00955: name is already used by an existing object"

We are trying to use Flyway to manage our database schema updates with the following spring-boot configuration:
spring:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
password: ${java_user_password}
url: ${DB_URL}
username: JAVA_USER
flyway:
locations: classpath:/db/migration
user: SUPER_USER
password: ${password_of_super_user}
baseline-on-migrate: true
url: ${DB_URL}
schema: JAVA_USER
Flyway version 5.1.4.
The configuration is working in Oracle 12.1.0.2.0 Standard Edition but not in Enterprise edition. We keep getting the following error:
SQL State : 42000
Error Code : 955
Message : ORA-00955: name is already used by an existing object
Line : 17
Statement : CREATE TABLE "JAVA_USER"."flyway_schema_history" (
"installed_rank" INT NOT NULL,
"version" VARCHAR2(50),
"description" VARCHAR2(200) NOT NULL,
"type" VARCHAR2(20) NOT NULL,
"script" VARCHAR2(1000) NOT NULL,
"checksum" INT,
"installed_by" VARCHAR2(100) NOT NULL,
"installed_on" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
"execution_time" INT NOT NULL,
"success" NUMBER(1) NOT NULL
)
Any idea why? Before starting the spring-boot application we delete all objects under the schemas.
Thanks!

Can not delete User with FOSOAuthBundle enabled

I try to delete a user in my symfony 3 app. I use the FOSOAuthBundle and the FOSUserBundle.
I tried this code:
$em = $this->getDoctrine()->getManager();
$em->remove($user);
$em->flush();
But I get this error:
An exception occurred while executing 'DELETE FROM user WHERE id = ?' with params [1]:\n\nSQLSTATE[23000]:
Integrity constraint violation: 1451 Cannot delete or update a parent row:
a foreign key constraint fails (`database`.`access_token`, CONSTRAINT `FK_B6A2DD68A76ED395` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`))
I have this configuration:
# FOSOAuthServerBundle configuration
fos_oauth_server:
db_driver: orm
client_class: OAuthBundle\Entity\Client
access_token_class: OAuthBundle\Entity\AccessToken
refresh_token_class: OAuthBundle\Entity\RefreshToken
auth_code_class: OAuthBundle\Entity\AuthCode
service:
user_provider: fos_user.user_provider.username_email
options:
access_token_lifetime: 86400
refresh_token_lifetime: 2.628e+6
If I get a access token the user field is always null though in the database the correct id is saved and it is possible to login with this token.
YOu need to configure cascade operations. You need to decide what do you want to happen on access_token table when you delete an user. You can delete de token or set the related user as null.
More info here

Symfony2 SyliusRbacBundle Setup

I am exploring the option of using SyliusRbacBundle for my app. I manage to install it along with FosUserBundle. When I got to the setup part I got the following error on running the command 'sylius:rbac:initialize' following the instructions found here: http://docs.sylius.org/en/latest/bundles/SyliusRbacBundle/setup.html#setup-roles-and-permissions-in-the-database
Initializing Sylius RBAC roles and permissions.
Adding permission "Update product". (app.product_update)
Adding permission "Create product". (app.product_create)
Adding permission "Manage product". (app.product_manage)
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'INSERT INTO sylius_role (code, name,
description, security_roles, tree_left, tree_right, tree_level, created_at
, updated_at, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params
["root", "Root", null, "a:0:{}", null, null, null, "2015-05-11 16:45:34",
"2015-05-11 16:45:34", null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tree_left' ca
nnot be null
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tree_left' ca
nnot be null
sylius:rbac:initialize
This is how my config.yml looks like:
sylius_rbac:
driver: doctrine/orm
security_roles:
ROLE_ADMINISTRATION_ACCESS: Can access backend
roles:
app.admin:
name: Administrator
description: Administrator
app.product_manager:
name: Product Manager
description: muchos productos
permissions: [app.product_update, app.product_create]
roles_hierarchy:
app.admin: [app.product_manager]
permissions:
app.product_update: Update product
app.product_create: Create product
app.product_manage: Manage product
permissions_hierarchy:
app.product_manage: [app.product_create, app.product_update]
Any one has a clue how to solve it?
Thanks!
The Sylius/Rbac uses the tree behaviour from the Atlantic18/DoctrineExtensions.
You can use this in a Symfony system using the stof/StofDoctrineExtensionsBundle.
Once it has been installed you would need to enable the tree behaviour in your app/config/config.yml like..
stof_doctrine_extensions:
orm:
default:
tree: true
This should make the listener register correctly and then your fields to be auto-populated.

Symfony - can't get multiple file upload to work

I'm using VichUploaderBundle to upload files for a gallery. I have two entities - the first one is Gallery, and the second is GalleryImage.
THis is the code:
http://pastebin.com/2nWAK2iH - Gallery Entity
http://pastebin.com/JWzWzZp2 - GalleryImage Entity
http://pastebin.com/TnZr24Sp - GalleryImageType Form
http://pastebin.com/9C8H25sn - GalleryType Form
http://tny.cz/26e859f6 - The Controller (part of it)
No matter what I do, I always get
"An exception occurred while executing 'INSERT INTO GalleryImage (image_name, gallery_id) VALUES (?, ?)' with params [null, 8]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'image_name' cannot be null"
Any ideas what I'm doing wrong?
Thanks
UPDATE
The new GalleryImage file: http://pastebin.com/uKtqg4HE
Looks like the #Uploadable class annotation is missing in the GalleryImage class.

How to generate entities from database view with doctrine and symfony2

I am trying to generate entities from database using standard console commands as described in Symfony2 documentation here: http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html.
php app/console doctrine:mapping:convert --from-database --force yml "src/My/HomeBundle/Resources/config/doctrine/metadata/orm"
php app/console doctrine:mapping:import MyHomeBundle yml
php app/console doctrine:generate:entities MyHomeBundle
After this, all tables are generated correctly. The problem is that this won't generate entities for database views. When I add yml files myself into src/My/HomeBundle/Resources/config/doctrine/metadata/orm for example:
UserInGroup:
type: entity
table: user_in_group_view
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
userId:
type: integer
unsigned: false
nullable: false
column: user_id
userGroupId:
type: integer
unsigned: false
nullable: false
column: user_group_id
lifecycleCallbacks: { }
I get this exception when running php app/console doctrine:generate:entities MyHomeBundle:
Notice: Undefined index: My\HomeBundle\Entity\UserInGroup in C:\Users\ThisIsMe\Projects\SymfonyTestProject\vendor\doctrine\lib\Doctrine\ORM\Mapping\Driver\AbstractFileDriver.php line 121
Similar question was posted here: How to set up entity (doctrine) for database view in Symfony 2
I know I can create Entity class, but I was hoping that I could get this generated so if I change my view, I could just regenerate entity classes. Any suggestions?
Now you create your orm files only. You need to follow 2 more steps. I will give you the complete steps from begining.
Before doing this delete all yml files in your orm directory that you had created early.
I hope MyHomeBundle is your bundle name
1).php app/console doctrine:mapping:convert yml ./src/My/HomeBundle/Resources/config/doctrine --from-database --force
Symfony2 generate entity from Database
2).php app/console doctrine:mapping:import MyHomeBundle yml
3).php app/console doctrine:generate:entities MyHomeBundle
Hope this helps you.
Got the same issue, i use xml instead of yml but must be the same.
Check in your orm entity if the name include the correct route, exemple:
<entity name="Myapp\MyrBundle\Entity\MyEntity" table="myentity">
Because when i generate my orm from database the name was like that:
<entity name="MyEntity" table="myentity">
So doctrine didn't understand the right path.
Hope i'm clear and this will help you!
I know it's an old question but I found the trick (Symfony 6) to generate entities from SQL view (I use a SQL server database).
So I modified two methods of the SQLServerPlatform.php file of the doctrine bundle.
public function getListTablesSQL()
{
// "sysdiagrams" table must be ignored as it's internal SQL Server table for Database Diagrams
// Category 2 must be ignored as it is "MS SQL Server 'pseudo-system' object[s]" for replication
return 'SELECT name, SCHEMA_NAME (uid) AS schema_name FROM sysobjects'
. " WHERE type = 'V' AND name != 'sysdiagrams' AND category != 2 ORDER BY name";
}
I changed the where condition parameter 'U' by 'V' for view.
Same operation for the method getListTableColumnsSQL(), we change here the 'U' parameter of the where condition by 'V'.
public function getListTableColumnsSQL($table, $database = null)
{
return "SELECT col.name,
type.name AS type,
col.max_length AS length,
~col.is_nullable AS notnull,
def.definition AS [default],
col.scale,
col.precision,
col.is_identity AS autoincrement,
col.collation_name AS collation,
CAST(prop.value AS NVARCHAR(MAX)) AS comment -- CAST avoids driver error for sql_variant type
FROM sys.columns AS col
JOIN sys.types AS type
ON col.user_type_id = type.user_type_id
JOIN sys.objects AS obj
ON col.object_id = obj.object_id
JOIN sys.schemas AS scm
ON obj.schema_id = scm.schema_id
LEFT JOIN sys.default_constraints def
ON col.default_object_id = def.object_id
AND col.object_id = def.parent_object_id
LEFT JOIN sys.extended_properties AS prop
ON obj.object_id = prop.major_id
AND col.column_id = prop.minor_id
AND prop.name = 'MS_Description'
WHERE obj.type = 'V'
AND " . $this->getTableWhereClause($table, 'scm.name', 'obj.name');
}
Maybe this will help someone.
As you can see here:
http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
the reverse engineering process from db to entity is not fully implemented yet:
"As the Doctrine tools documentation says, reverse engineering is a one-time process to get started on a project. Doctrine is able to convert approximately 70-80% of the necessary mapping information based on fields, indexes and foreign key constraints. Doctrine can't discover inverse associations, inheritance types, entities with foreign keys as primary keys or semantical operations on associations such as cascade or lifecycle events. Some additional work on the generated entities will be necessary afterwards to design each to fit your domain model specificities."

Resources