Unknown column <tablename>_id on Shopware 6 translations - shopware

After creating a Shopware6 Entity with translations,
exactly following the official tutorial,
I get an Unknown column "<tablename>_id" error; the tablename seems to be interpreted as part of the column name.

There is a requirement on the naming scheme of mapped fields in the *_translation tables:
they HAVE to follow <tablename>_id. That is, the tablename IS part of the fieldname.
In the tutorial that's not obvious, since they speak of bundle_id, where "bundle" is not the name of the entity but the table name. Most likely you vendor-prefixed and modulename-prefixed your table.
Example:
Your Entity: ACME\CoolModule\Core\Content\FoobarDefinition
Entity Table:
acme_coolmodule_foobar
Translation-table HAS to be exactly:
CREATE TABLE IF NOT EXISTS `acme_coolmodule_foobar_translation` (
`acme_coolmodule_foobar_id` BINARY(16) NOT NULL,
`language_id` BINARY(16) NOT NULL, ...
The difficulty is that Shopware doesn't SWAG-Prefix their own tutorial-modules, so you can't see the difference.

Related

How to fetch Primary Key/Clustering column names for a particular table using CQL statements?

I am trying to fetch the Primary Key/Clustering Key names for a particular table/entity and implement the same query in my JPA interface (which extends CassandraRepository).
I am not sure whether something like:
#Query("DESCRIBE TABLE <table_name>)
public Object describeTbl();
would work here as describe isn't a valid CQL statement and in case it would, what would be the type of the Object?
Suggestions?
One thing you could try, would be to query the system_schema.columns table. It is keyed by keyspace_name and table_name, and might be what you're looking for here:
> SELECT column_name,kind FROM system_schema.columns
WHERE keyspace_name='spaceflight_data'
AND table_name='astronauts_by_group';
column_name | kind
-------------------+---------------
flights | regular
group | partition_key
name | clustering
spaceflight_hours | clustering
(4 rows)
DESCRIBE TABLE is supported only in Cassandra 4 that includes fix for CASSANDRA-14825. But it may not help you much because it just returns the text string representing the CREATE TABLE statement, and you'll need to parse text to extract primary key definition - it's doable but could be tricky, depending on the structure of the primary key.
Or you can obtain underlying Session object and via getMetadata function get access to actual metadata object that allows to obtain information about keyspaces & tables, including the information about schema.

Cassandra, Delete if a set contains value

I'm a beginner in Cassandra and I have a table like this:
CREATE TABLE Books(
Title text PRIMARY KEY,
Authors set<text>,
Family set <text>,
Publisher text,
Price decimal
);
(the other options are missing because it's only an example)
now I would like to execute this query:
DELETE Price FROM Books WHERE Authors CONTAINS 'J.K. Rowling' IF EXISTS;
But it doesn't work. I searched on Google but found nothing.
Hope somebody can help me and sorry if my english is not very good.
but it doesn't work.
That doesn't really give us enough information to help you. Usually, you'll want to provide an error message. I built your table locally, inserted data, and tried your approach. This is the error that I see:
InvalidRequest: Error from server: code=2200 [Invalid query]
message="Some partition key parts are missing: title"
DELETE requires that the appropriate PRIMARY KEY components be specified in the WHERE clause. In your case, Authors is not part of the PRIMARY KEY definition. Given the error message returned (and the table definition) specifying title is the only way to delete rows from this table.
aploetz#cqlsh:stackoverflow> DELETE FROM Books
WHERE title = 'Harry Potter and the Chamber of Secrets'
IF EXISTS;
[applied]
-----------
True
Can I do a query like this? UPDATE Books SET Family = Family + {'Fantasy'} WHERE Authors CONTAINS 'J.K. Rowling';
No. This fails for the same reason. Writes in Cassandra (INSERTs, UPDATEs, DELETEs are all writes) require the primary key (specifically, the partition key) in the WHERE clause. Without that, Cassandra can't figure out which node holds the data, and it needs that to perform the write.

unable to upsert using java datastax driver

I am unable to upsert a row using the datastax driver.
The data in the Cassandra table is stored like follows:
tag | partition_info
------------+--------------------------------------------------
sometag | {{year: 2018, month: 1}, {year: 2018, month: 2}}
tag is primary key and partition_info is a UDT
CREATE TYPE codingjedi.tag_partitions (
year bigint,
month bigint
);
I want that if a tag doesn't exist then it gets created. If tag exists then the new udt value gets appended to old one. I suppose I cannot use insert as it overrides previous value i.e. this will not work
QueryBuilder.insertInto(tableName).value("tag",model.tag)
.value("partition_info",setAsJavaSet(Set(partitionsInfo)))
I am trying to use update but it isn't working. Datastax driver gives error java.lang.IllegalArgumentException for following query
QueryBuilder.update(tableName).`with`(QueryBuilder.append("partition_info",setAsJavaSet(Set(partitionsInfo))))
.where(QueryBuilder.eq("tag", id.tag))
I tried using add and append for primary key but but got the error PRIMARY KEY part tag found in SET part
QueryBuilder.update(tableName).`with`(QueryBuilder.add("tag",id.tag))
.and(QueryBuilder.append("partition_info",setAsJavaSet(Set(partitionsInfo)))) .where(QueryBuilder.eq("tag", id.tag))
You're using the incorrect operation in your update statement - you're using append, but it's used to append data to columns of list types. You can use instead either add if you're adding a single value (your case, so you wont even need to wrap data into Set explicitly), or addAll if you're adding multiple values.
QueryBuilder.update(tableName)
.`with`(QueryBuilder.add("partition_info", partitionsInfo))
.where(QueryBuilder.eq("tag", id.tag))

Postgres syntax error for reference

I am trying to create a table with the following query using the pg npm module (v7):
CREATE TABLE subscriptions(
id SERIAL PRIMARY KEY,
stripe_id VARCHAR(40) UNIQUE NOT NULL,
user INTEGER REFERENCES users,
plan VARCHAR(40) NOT NULL,
active BOOLEAN NOT NULL,
start DATE NOT NULL,
end DATE DEFAULT NULL
);
This seems to match the docs but it is throwing an error:
error: syntax error at or near "user"
The users table has a serial primary key for id, anyone know why this isn't working?
Edit: here's the docs for reference - https://www.postgresql.org/docs/9.4/static/ddl-constraints.html#DDL-CONSTRAINTS-FK
I'm using postgresql version 9.4.
user is a reserved keyword in postgresql. You may use any other column name in its place
Refer the postgresql documentation for the complete list of keywords - Key Words List
According to it, end is also reserved. So the last line of your code will generate an error

Unable to update the EntitySet (no insert function)

I have this tables in my data base:
Videos(IDVideo, Name...)
Episodes(IDEpisode, Name...)
Versions(IDVersion, Name, ....)
VideosVersions(IDVideo, IDEpisode, IDVersion)
A version can be for a video or for the episode and the relation in both cases is N:N, a video can have many versions and a version can be asigned to many videos or episodes.
In my edmx model has the four tables.
When I try to assign a new version to a video for example I use this code:
VideosVersions myVideoVersion = new VideosVersions();
myVideoVersion.IDVideo = paramVideo.IDVideo;
myVideoVersion.IDVersion = paramVersion.IDVersion;
myContext.VideosVersions.Add(myVideosVersions);
myContext.SaveChanges();
But I get the following exception:
Unable to update the EntitySet 'VideosVersions' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.
Why?
Thanks.
EDIT: in my entity in the edmx model the three properites has a key, so if I am not wrong, this means that the PK of the entity is the combination of the three fields, is correct?
The mapper probably couldn't figure out which columns should be the primary key of VideosVersions. This means it doesn't know how to insert new records and only provides the query method. Make sure you have the primary key properly defined on the table, then update the mapping.

Resources