How to set optional cascade peristance - symfony

I have set cascade persist in my Entity for OneToOne relation and it works well until I leave field nullable. Is possible to allow leave the field blank?
/**
* #var array
*
* #ORM\OneToOne(targetEntity="CoreBundle\Entity\Campaign\TaskPrize", mappedBy="task", cascade={"persist"})
*/
private $prize;
Error:
{"code":500,"message":"An exception occurred while executing 'INSERT INTO campaign_task_prize (type, url, disposable, shipping_by_post, created_at, updated_at, task_id) VALUES (?, ?, ?, ?, ?, ?, ?)' with params [null, null, 0, 0, \"2017-07-13 12:26:21\", \"2017-07-13 12:26:21\", null]:\n\nSQLSTATE[23000]: Integrity constraint violation: 1048 Column 'type' cannot be null"}

Related

Symfony Doctrine Flush Returning Null

I'm trying to create a system that will recreate a new shift when given a date array example [0,3,4] for the same day, 3 days away and 4 days away. When I create a single shift I am able to persist and flush to the database with no problem at all.
My Issue is when I create my $newShifts in a forloop persist them and once all are persisted (9 for example) I go to flush and get the following.
An exception occurred while executing 'INSERT INTO guard_shift (shift_start, shift_end, actual_shift_start, actual_shift_end, approved, deletedAt, user_id, admin_id, site_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)' with params [null, null, null, null, false, null, 1, 1, 8]:\n\nSQLSTATE[23000]: Integrity constraint violation: 1048 Column 'shift_start' cannot be null",
"class": "Doctrine\\DBAL\\Exception\\NotNullConstraintViolationException
If I dd $newShift->getStartShift before the flush I get 9 start times.
This Gist is both the controller endpoint and my helper combined in one file for ease of sharing.
https://gist.github.com/George-Farrell/86524c53f3218dbd1cbfd003b7666df6
The code in the gist looks very raw and needs refactoring to more obvious steps and more small functions for the sake of readability.
My suggestion is that this function is the root of the problem:
when $clashingId is true, you can't persist a new shift, because the result of the function is already returned.
private function flushShift($admin,$shiftStart,$shiftFinish,$user,$site)
{
$newShift = new GuardShift();
$newShift->setAdmin($admin);
$newShift->setShiftStart($this->timestamp->reverseTransform(strtotime($shiftStart)));
$newShift->setShiftEnd($this->timestamp->reverseTransform(strtotime($shiftFinish)));
$newShift->setUser($user);
$newShift->setSite($site);
$clashingId = $this->isShiftClashing(
$shiftStart,
$shiftFinish,
$admin,
$user
);
if ($clashingId == true) {
$clash = $this->entityManager->getRepository(GuardShift::class)->findOneBy(['id' => $clashingId]);
$data = $this->serialize->serialize($clash, 'json', SerializationContext::create()->enableMaxDepthChecks());
return new JsonResponse($data, Response::HTTP_CONFLICT, [], true);
}
$this->entityManager->persist($newShift);
}

While making the bid in any one console i am getting this error in the cordapp-auction project

E 12:59:13+0530 [Node thread-1] spi.SqlExceptionHelper.logExceptions - Unique index or primary key violation: "PRIMARY_KEY_D ON PUBLIC.TRADE_STATES(OUTPUT_INDEX, TRANSACTION_ID) VALUES (0, '26EF53AD8C3CC7A99344B65B8469655FE9FE8ABB8DF98E1FEAC32425E122BFE4', 2)"; SQL statement:
insert into trade_states (amount, auctionReference, bidder, itemOwner, linear_id, output_index, transaction_id) values (?, ?, ?, ?, ?, ?, ?) [23505-194] {}
E 14:58:49+0530 [Node thread-1] spi.SqlExceptionHelper.logExceptions - Unique index or primary key violation: "PRIMARY_KEY_C ON PUBLIC.VAULT_STATES(OUTPUT_INDEX, TRANSACTION_ID) VALUES (0, '6FA36D1F62B0B20F9A4903AA175655E0D567116DB63D802DC7A6CB6E2C3EE3AE', 14)"; SQL statement:
insert into vault_states (consumed_timestamp, contract_state_class_name, lock_id, lock_timestamp, notary_name, recorded_timestamp, state_status, output_index, transaction_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-194] {}
E 14:58:49+0530 [Node thread-1] internal.ExceptionMapperStandardImpl.mapManagedFlushFailure - HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement] {}
ok when i am trying to make the bid from anyone console it is showing this error
2nd error
list is empty
when i am trying to close the auction
the project is from github (https://github.com/vardan10/cordapp-auction)
anyone can help me with this errors
Unfortunately, we will not be able to identify the issue with the above information. We would need more details for debug.
Furthermore, please refer to this official repository https://github.com/corda/samples for cordapp sample reference.

Symfony EasyAuditBundle error when insert into table

I got this error when it try to insert into the audit_lo table
An exception occurred while executing 'INSERT INTO audit_log (id,
type_id, type, description, event_time, user, impersonatingUser, ip)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)' with params [5,
"security.interactive_login", "security.interactive_login",
"security.interactive_login", "2017-11-22 12:56:48", "bmellor", null,
"::1"]:
and this log
Uncaught PHP Exception Doctrine\DBAL\Exception\SyntaxErrorException:
"An exception occurred while executing 'INSERT INTO audit_log (id,
type_id, type, description, event_time, user, impersonatingUser, ip)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)' with params [5,
"security.interactive_login", "security.interactive_login",
"security.interactive_login", "2017-11-22 12:56:48", "bmellor", null,
"::1"]: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error in or
close to «user» LINE 1: ..._log (id, type_id, type, description,
event_time, user, impe... ^" at
/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
line 70
I follow all the steps in here and inside config.yml
xiidea_easy_audit:
entity_class : AppBundle\Entity\AuditLog #Required
user_property : username #Optional
doctrine_entities : #Optional
AppBundle\Entity\SomeEntity : [created, updated, deleted]
events : #Optional
- security.interactive_login
EDIT
Environment
PHP 7.1.11
Symfony 3.3.X
PostgreSQL 9.6
EasyAuditBundle ^1.4
I've answer this question with 2 steps:
It seems like postgreSQL the column USER is reserved so I change it to user_data inside the entity
Changed impersonatingUser to nullable=true
And that works for me.

insert fail in a table that have composite key in Doctrine-symfony2

when i insert in a table that has composite key of two fields , it fail and say it is null insertion , once i delete the composite key it insert successfully.
An exception occurred while executing 'INSERT INTO course_to_category (courseId, categoryId, ordering) VALUES (?, ?, ?)' with params [null, null, 1]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'courseId' cannot be null
Seems like your composite key is primary key. Check this:
A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently). A table can have only one PRIMARY KEY. The name of a PRIMARY KEY is always PRIMARY, which thus cannot be used as the name for any other kind of index.
http://dev.mysql.com/doc/refman/5.1/en/create-table.html

ASP.NET and SQL - inserting data into more than one table?

So I know similar questions have been asked before, but I couldn't find a clear answer for my specific situation. I'm using ASP.NET (in Visual Web Developer) and I need to insert data from one form into two separate tables. This is my data source:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/courseinfo.mdb"
SelectCommand="SELECT * FROM [tableCourse], [tableFaculty]"
InsertCommand="INSERT INTO [tableCourse]
([department], [name_first], [name_last], [prefix],
[course_number], [credits], [title], [description])
VALUES (?, ?, ?, ?, ?, ?, ?, ?); INSERT INTO [tableFaculty] ([name_first], [name_last], [phone], [email])
VALUES (?, ?, ?, ?)">
So you see I've tried using two insert statements, and it just comes back with an error saying there are extra characters after the SQL statement. I've tried taking out the semi-colon and then it says I'm missing a semi-colon. Is it possible to insert to two tables at once using this control? And if not, how do I work around this?
UPDATE:
Okay, tried it in the codebehind, but I don't think I did it right, now it's giving me this error:
Server Error in '/CCC' Application.
Index or primary key cannot contain a Null value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Index or primary key cannot contain a Null value.
Source Error:
Line 87:
Line 88: AccessDataSource1.InsertCommand = "INSERT INTO [tableCourse] ([department], [name_first], [name_last], [prefix], [course_number], [credits], [title], [description]) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
Line 89: AccessDataSource1.Insert()
Line 90:
Line 91: AccessDataSource1.InsertCommand = "INSERT INTO [tableFaculty] ([name_first], [name_last], [phone], [email]) VALUES (?, ?, ?, ?)"
Line 89 is the one that's highlighted. So I'm thinking it's attempting to insert but for some reason the values are null, it isn't taking the values from the text boxes.
I probably left something obvious out, I don't know, I'm really new at this.
Why don't you give it a try at the codebehind?
AccessDataSource1.InsertCommand = "First INSERT Statement";
AccessDataSource1.Insert();
AccessDataSource1.InsertCommand = "Second INSERT Statement";
AccessDataSource1.Insert();

Resources